Esempio n. 1
0
        public void InArcsCountOr()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 4);

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

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

            graph.DeleteArc(1, 2);

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

            graph.DeleteArc(0, 1);

            Assert.AreEqual(0, graph.InArcsCount(0));
            Assert.AreEqual(0, graph.InArcsCount(1));
            Assert.AreEqual(1, graph.InArcsCount(2));
            Assert.AreEqual(1, graph.InArcsCount(3));
        }
Esempio n. 2
0
        public void DeleteArcOr()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 4);

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

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

            graph.DeleteArc(1, 2);

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

            graph.DeleteArc(0, 1);

            Assert.IsFalse(graph.ContainsArc(0, 1));
            Assert.IsFalse(graph.ContainsArc(1, 0));
            Assert.IsTrue(graph.ContainsArc(0, 2));
            Assert.IsFalse(graph.ContainsArc(2, 0));
            Assert.IsFalse(graph.ContainsArc(1, 2));
            Assert.IsFalse(graph.ContainsArc(2, 1));
            Assert.IsTrue(graph.ContainsArc(1, 3));
            Assert.IsFalse(graph.ContainsArc(3, 1));
            Assert.IsFalse(graph.ContainsArc(0, 3));
            Assert.IsFalse(graph.ContainsArc(3, 0));
            Assert.IsFalse(graph.ContainsArc(2, 3));
            Assert.IsFalse(graph.ContainsArc(3, 2));
        }
Esempio n. 3
0
        public void DeleteArcIncorrect()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(false, 3);

            graph.AddArc(0, 1);
            graph.DeleteArc(1, 2);
        }
Esempio n. 4
0
        public void DeleteArcIncorrectOrInverse()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 2);

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

            graph.DeleteArc(1, 0);
        }
Esempio n. 5
0
        public void Combine()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(false, 2);

            Assert.IsFalse(graph.Oriented);
            Assert.AreEqual(2, graph.PeakCount);

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

            graph.AddArc(0, 1);

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

            Assert.AreEqual(1, 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.OutGoingArcs(1).Count() == 1);
            foreach (var e in graph.OutGoingArcs(1))
            {
                Assert.AreEqual(0, e);
            }

            Assert.IsTrue(graph.InComingArcs(0).Count() == 1);
            foreach (var e in graph.InComingArcs(0))
            {
                Assert.AreEqual(1, 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.IsTrue(graph.ContainsArc(2, 0));
            Assert.AreEqual(2, graph.InArcsCount(0));
            Assert.AreEqual(1, graph.InArcsCount(2));

            int[] zeroIn    = { 1, 2 };
            int   zeroInInd = 0;

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

            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() == 1);
            foreach (var e in graph.OutGoingArcs(2))
            {
                Assert.AreEqual(0, e);
            }

            graph.AddPeak();
            graph.AddArc(3, 2);
            graph.DeleteArc(2, 0);
            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.IsTrue(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() == 1);
            foreach (var e in graph.OutGoingArcs(1))
            {
                Assert.AreEqual(2, e);
            }

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

            // Вторая

            Assert.AreEqual(1, 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() == 1);
            foreach (var e in graph.InComingArcs(2))
            {
                Assert.AreEqual(1, e);
            }


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

            Assert.IsFalse(graph.Oriented);
            Assert.AreEqual(3, graph.PeakCount);
        }
Esempio n. 6
0
        public void DeleteArcNotExistPeakOr()
        {
            UnweightedGraphMatrix graph = new UnweightedGraphMatrix(true, 3);

            graph.DeleteArc(4, 1);
        }