Пример #1
0
        public void DeleteArcIncorrectOrInverse()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();

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

            graph.DeleteArc(1, 0);
        }
Пример #2
0
        public void AddArcTwoDirOr()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();

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

            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsTrue(graph.ContainsArc(1, 0));
        }
Пример #3
0
        public void ThreeElFromEndInorrect()
        {
            UnweightedGraphList graph = new UnweightedGraphList(false);

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

            graph.RemovePeak(2);

            Assert.IsTrue(graph.ContainsArc(2, 1));
            Assert.IsTrue(graph.ContainsArc(1, 2));
        }
Пример #4
0
        public void ThreeElFromMiddleCorrect()
        {
            UnweightedGraphList graph = new UnweightedGraphList(false);

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

            graph.RemovePeak(1);

            Assert.AreEqual(2, graph.PeakCount);
            Assert.IsTrue(graph.ContainsArc(1, 0));
            Assert.IsTrue(graph.ContainsArc(0, 1));
        }
Пример #5
0
        public void FiveModern()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();

            Dictionary <char, int> peakCodes = new Dictionary <char, int>
            {
                ['a'] = 0,
                ['b'] = 1,
                ['c'] = 2,
                ['d'] = 3,
                ['e'] = 4
            };

            graph.AddArc(peakCodes['a'], peakCodes['b']);
            graph.AddArc(peakCodes['b'], peakCodes['c']);
            graph.AddArc(peakCodes['c'], peakCodes['d']);
            graph.AddArc(peakCodes['d'], peakCodes['e']);
            graph.AddArc(peakCodes['e'], peakCodes['a']);

            graph.RemovePeak(peakCodes['c']);
            peakCodes.Remove('c');
            peakCodes['d'] = 2;
            peakCodes['e'] = 3;

            Assert.AreEqual(4, graph.PeakCount);
            Assert.IsTrue(graph.ContainsArc(peakCodes['a'], peakCodes['b']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['d'], peakCodes['e']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['e'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['a'], peakCodes['d']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['d']));

            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['e'], peakCodes['d']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['a'], peakCodes['e']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['b']));

            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['e']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['e'], peakCodes['b']));

            graph.RemovePeak(peakCodes['e']);
            peakCodes.Remove('e');

            Assert.AreEqual(3, graph.PeakCount);
            Assert.IsTrue(graph.ContainsArc(peakCodes['a'], peakCodes['b']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['a'], peakCodes['d']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['d']));

            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['a'])); // ??? - ошибка
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['b']));
        }
Пример #6
0
        public void SevenElFromMiddleCorrect()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();

            PeakCodes peakCounts = new PeakCodes()
            {
                'a', 'b', 'c', 'd', 'e', 'f', 'g'
            };

            //Необходимость сортировки
            graph.AddArc(peakCounts['g'], peakCounts['f']);
            graph.AddArc(peakCounts['g'], peakCounts['e']);

            graph.AddArc(peakCounts['a'], peakCounts['b']);
            graph.AddArc(peakCounts['b'], peakCounts['c']);
            graph.AddArc(peakCounts['c'], peakCounts['b']);

            graph.AddArc(peakCounts['a'], peakCounts['d']);
            graph.AddArc(peakCounts['d'], peakCounts['b']);
            graph.AddArc(peakCounts['c'], peakCounts['d']);
            graph.AddArc(peakCounts['d'], peakCounts['c']);

            graph.AddArc(peakCounts['e'], peakCounts['f']);
            graph.AddArc(peakCounts['f'], peakCounts['e']);

            graph.AddArc(peakCounts['e'], peakCounts['d']);
            graph.AddArc(peakCounts['d'], peakCounts['e']);
            graph.AddArc(peakCounts['d'], peakCounts['f']);
            graph.AddArc(peakCounts['g'], peakCounts['d']);

            graph.AddArc(peakCounts['a'], peakCounts['e']);
            graph.AddArc(peakCounts['f'], peakCounts['b']);
            graph.AddArc(peakCounts['c'], peakCounts['g']);
            graph.AddArc(peakCounts['g'], peakCounts['c']);

            graph.RemovePeak(peakCounts['d']);
            peakCounts.Remove('d');


            Assert.IsTrue(graph.ContainsArc(peakCounts['a'], peakCounts['b']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['a'], peakCounts['c']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['a'], peakCounts['e']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['a'], peakCounts['f']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['a'], peakCounts['g']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['b'], peakCounts['a']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['b'], peakCounts['c']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['b'], peakCounts['e']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['b'], peakCounts['f']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['b'], peakCounts['g']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['c'], peakCounts['a']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['c'], peakCounts['b']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['c'], peakCounts['e']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['c'], peakCounts['f']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['c'], peakCounts['g']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['e'], peakCounts['a']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['e'], peakCounts['c']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['e'], peakCounts['b']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['e'], peakCounts['f']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['e'], peakCounts['g']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['f'], peakCounts['a']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['f'], peakCounts['c']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['f'], peakCounts['e']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['f'], peakCounts['b']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['f'], peakCounts['g']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['g'], peakCounts['a']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['g'], peakCounts['c']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['g'], peakCounts['e']));
            Assert.IsTrue(graph.ContainsArc(peakCounts['g'], peakCounts['f']));
            Assert.IsFalse(graph.ContainsArc(peakCounts['g'], peakCounts['b']));
        }
Пример #7
0
        public void FiveElFromMiddleCorrect()
        {
            UnweightedGraphList graph = new UnweightedGraphList(false);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();

            Dictionary <char, int> peakCodes = new Dictionary <char, int>
            {
                ['a'] = 0,
                ['b'] = 1,
                ['c'] = 2,
                ['d'] = 3,
                ['e'] = 4
            };

            graph.AddArc(peakCodes['a'], peakCodes['b']);
            graph.AddArc(peakCodes['b'], peakCodes['c']);
            graph.AddArc(peakCodes['c'], peakCodes['d']);
            graph.AddArc(peakCodes['d'], peakCodes['e']);
            graph.AddArc(peakCodes['e'], peakCodes['a']);

            graph.RemovePeak(peakCodes['c']);
            peakCodes.Remove('c');
            peakCodes['d'] = 2;
            peakCodes['e'] = 3;

            Assert.AreEqual(4, graph.PeakCount);
            Assert.IsTrue(graph.ContainsArc(peakCodes['a'], peakCodes['b']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['d'], peakCodes['e']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['e'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['a'], peakCodes['d']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['d']));

            Assert.IsTrue(graph.ContainsArc(peakCodes['b'], peakCodes['a']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['e'], peakCodes['d']));
            Assert.IsTrue(graph.ContainsArc(peakCodes['a'], peakCodes['e']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['d'], peakCodes['b']));

            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['e']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['e'], peakCodes['b']));
        }
Пример #8
0
        public void AddArc()
        {
            UnweightedGraphList graph = new UnweightedGraphList(false);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();

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

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

            graph.AddArc(2, 0);

            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsTrue(graph.ContainsArc(1, 0));
            Assert.IsTrue(graph.ContainsArc(1, 2));
            Assert.IsTrue(graph.ContainsArc(2, 1));
            Assert.IsTrue(graph.ContainsArc(0, 2));
            Assert.IsTrue(graph.ContainsArc(2, 0));
        }
Пример #9
0
        public void DeleteArcOr()
        {
            UnweightedGraphList graph = new UnweightedGraphList(true);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();

            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));
        }
Пример #10
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);
        }