Exemplo n.º 1
0
        public void OutGoingArcsOrEmptyPeak()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddArc(0, 1);

            Assert.IsTrue(graph.OutGoingArcs(2).Count() == 0);
            foreach (var e in graph.OutGoingArcs(2))
            {
                Assert.AreEqual(0, graph.OutGoingArcs(2));
                Assert.AreEqual(0, e);
            }
        }
Exemplo n.º 2
0
        public void OutGoingArcsOr()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddArc(0, 1);
            graph.AddArc(0, 2);
            graph.AddArc(1, 0);
            graph.AddArc(1, 2);
            graph.AddArc(2, 0);

            int i = 0;

            int[] zero = { 1, 2 };
            int[] one  = { 0, 2 };
            int[] two  = { 0 };

            foreach (var e in graph.OutGoingArcs(0))
            {
                Assert.IsTrue(graph.OutGoingArcs(0).Count() == zero.Length);
                Assert.IsTrue(zero[i] == e);
                i++;
            }

            i = 0;

            foreach (var e in graph.OutGoingArcs(1))
            {
                Assert.IsTrue(graph.OutGoingArcs(1).Count() == one.Length);
                Assert.IsTrue(one[i] == e);
                i++;
            }

            i = 0;

            foreach (var e in graph.OutGoingArcs(2))
            {
                Assert.IsTrue(graph.OutGoingArcs(2).Count() == two.Length);
                Assert.IsTrue(two[i] == e);
                i++;
            }
        }
Exemplo n.º 3
0
        public void CombineOr()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            Assert.IsTrue(graph.Oriented);
            Assert.AreEqual(2, graph.PeakCount);

            // AddArc ==================

            graph.AddArc(0, 1);

            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsFalse(graph.ContainsArc(1, 0));

            Assert.AreEqual(0, graph.InArcsCount(0));
            Assert.AreEqual(1, graph.InArcsCount(1));

            Assert.IsTrue(graph.OutGoingArcs(0).Count() == 1);
            foreach (var e in graph.OutGoingArcs(0))
            {
                Assert.AreEqual(1, e);
            }

            Assert.IsTrue(graph.InComingArcs(0).Count() == 0);
            foreach (var e in graph.InComingArcs(0))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.OutGoingArcs(1).Count() == 0);
            foreach (var e in graph.OutGoingArcs(1))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.InComingArcs(1).Count() == 1);
            foreach (var e in graph.InComingArcs(1))
            {
                Assert.AreEqual(0, e);
            }

            // AddPeak ==================

            graph.AddPeak();
            Assert.AreEqual(3, graph.PeakCount);

            graph.AddArc(0, 2);
            Assert.IsTrue(graph.ContainsArc(0, 2));
            Assert.IsFalse(graph.ContainsArc(2, 0));
            Assert.AreEqual(0, graph.InArcsCount(0));
            Assert.AreEqual(1, graph.InArcsCount(2));


            Assert.IsTrue(graph.InComingArcs(0).Count() == 0);
            foreach (var e in graph.InComingArcs(0))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.InComingArcs(2).Count() == 1);
            foreach (var e in graph.InComingArcs(2))
            {
                Assert.AreEqual(0, e);
            }

            int[] zeroOut    = { 1, 2 };
            int   zeroOutInd = 0;

            Assert.IsTrue(graph.OutGoingArcs(0).Count() == 2);
            foreach (var e in graph.OutGoingArcs(0))
            {
                Assert.AreEqual(zeroOut[zeroOutInd], e);
                zeroOutInd++;
            }

            Assert.IsTrue(graph.OutGoingArcs(2).Count() == 0);
            foreach (var e in graph.OutGoingArcs(2))
            {
                Assert.AreEqual(0, e);
            }

            graph.AddPeak();
            graph.AddArc(3, 2);

            Assert.AreEqual(2, graph.InArcsCount(2));

            graph.DeleteArc(0, 2);
            graph.RemovePeak(1);

            // Проверка ребер

            Assert.IsFalse(graph.ContainsArc(0, 1));
            Assert.IsFalse(graph.ContainsArc(1, 0));
            Assert.IsFalse(graph.ContainsArc(0, 2));
            Assert.IsFalse(graph.ContainsArc(2, 0));
            Assert.IsFalse(graph.ContainsArc(1, 2));
            Assert.IsTrue(graph.ContainsArc(2, 1));

            // Проверка вершин

            // Нулевая

            Assert.AreEqual(0, graph.InArcsCount(0));

            Assert.IsTrue(graph.OutGoingArcs(0).Count() == 0);
            foreach (var e in graph.OutGoingArcs(0))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.InComingArcs(0).Count() == 0);
            foreach (var e in graph.InComingArcs(0))
            {
                Assert.AreEqual(0, e);
            }

            // Первая

            Assert.AreEqual(1, graph.InArcsCount(1));

            Assert.IsTrue(graph.OutGoingArcs(1).Count() == 0);
            foreach (var e in graph.OutGoingArcs(1))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.InComingArcs(1).Count() == 1);
            foreach (var e in graph.InComingArcs(1))
            {
                Assert.AreEqual(2, e);
            }

            // Вторая

            Assert.AreEqual(0, graph.InArcsCount(2));

            Assert.IsTrue(graph.OutGoingArcs(2).Count() == 1);
            foreach (var e in graph.OutGoingArcs(2))
            {
                Assert.AreEqual(1, e);
            }

            Assert.IsTrue(graph.InComingArcs(2).Count() == 0);
            foreach (var e in graph.InComingArcs(2))
            {
                Assert.AreEqual(0, e);
            }

            // Завершение

            Assert.IsTrue(graph.Oriented);
            Assert.AreEqual(3, graph.PeakCount);
        }