Ejemplo n.º 1
0
        public void ThreePeaksAddArc()
        {
            WeightedGraphList <int> graph = new WeightedGraphList <int>(false);

            graph.AddPeak();
            graph.AddPeak();
            graph.AddPeak();
            graph.AddArc(0, 1, 32);
            graph.AddArc(1, 0, -32);
            graph.AddArc(1, 2, -64);
            graph.AddArc(2, 1, 64);
            graph.AddArc(0, 2, 128);

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

            Assert.AreEqual(-32, graph.GetWeight(1, 0));
            Assert.AreEqual(-32, graph.GetWeight(0, 1));
            Assert.AreEqual(64, graph.GetWeight(1, 2));
            Assert.AreEqual(64, graph.GetWeight(2, 1));
            Assert.AreEqual(128, graph.GetWeight(0, 2));
            Assert.AreEqual(128, graph.GetWeight(2, 0));

            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsTrue(graph.ContainsArc(0, 2));
            Assert.IsTrue(graph.ContainsArc(1, 0));
            Assert.IsTrue(graph.ContainsArc(1, 2));
            Assert.IsTrue(graph.ContainsArc(2, 0));
            Assert.IsTrue(graph.ContainsArc(2, 1));
        }
Ejemplo n.º 2
0
        public void CountAfter()
        {
            WeightedGraphList <int> graph = new WeightedGraphList <int>(false);

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

            PeakCodes peakCodes = new PeakCodes()
            {
                'a', 'b', 'c'
            };

            graph.AddArc(peakCodes['a'], peakCodes['b'], 31);
            graph.AddArc(peakCodes['b'], peakCodes['c'], 42);
            graph.AddArc(peakCodes['c'], peakCodes['a'], 45);

            Assert.AreEqual(3, graph.PeakCount);
            Assert.AreEqual(42, graph.GetWeight(peakCodes['b'], peakCodes['c']));
            Assert.AreEqual(42, graph.GetWeight(peakCodes['c'], peakCodes['b']));
            Assert.AreEqual(31, graph.GetWeight(peakCodes['a'], peakCodes['b']));
            Assert.AreEqual(31, graph.GetWeight(peakCodes['b'], peakCodes['a']));
            Assert.AreEqual(45, graph.GetWeight(peakCodes['c'], peakCodes['a']));
            Assert.AreEqual(45, graph.GetWeight(peakCodes['a'], peakCodes['c']));

            graph.RemovePeak(peakCodes['c']);

            Assert.AreEqual(2, graph.PeakCount);
            Assert.AreEqual(31, graph.GetWeight(peakCodes['a'], peakCodes['b']));
            Assert.AreEqual(31, graph.GetWeight(peakCodes['b'], peakCodes['a']));
        }
Ejemplo n.º 3
0
        public void AddArcRangeException()
        {
            WeightedGraphList <int> graph = new WeightedGraphList <int>(false);

            Assert.IsFalse(graph.Oriented);

            graph.AddPeak();
            Assert.AreEqual(1, graph.PeakCount);
            graph.AddPeak();
            Assert.AreEqual(2, graph.PeakCount);

            graph.AddArc(0, 2, 2);
        }
Ejemplo n.º 4
0
        public void AddArcRangeExceptionOriented()
        {
            WeightedGraphList <int> graph = new WeightedGraphList <int>(true);

            Assert.IsTrue(graph.Oriented);

            graph.AddPeak();
            Assert.AreEqual(1, graph.PeakCount);
            graph.AddPeak();
            Assert.AreEqual(2, graph.PeakCount);

            graph.AddArc(0, 1, 2);
            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsFalse(graph.ContainsArc(1, 0));
            Assert.AreEqual(2, graph.GetWeight(0, 1));
            Assert.AreEqual(20, graph.GetWeight(1, 0));
        }
Ejemplo n.º 5
0
        public void TwoPeaksAddArc()
        {
            WeightedGraphList <int> graph = new WeightedGraphList <int>(false);

            Assert.IsFalse(graph.Oriented);

            graph.AddPeak();
            Assert.AreEqual(1, graph.PeakCount);
            graph.AddPeak();
            Assert.AreEqual(2, graph.PeakCount);

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

            graph.AddArc(1, 0, 4);
            Assert.IsTrue(graph.ContainsArc(0, 1));
            Assert.IsTrue(graph.ContainsArc(1, 0));
            Assert.AreEqual(4, graph.GetWeight(0, 1));
            Assert.AreEqual(4, graph.GetWeight(1, 0));
        }
Ejemplo n.º 6
0
        public void MatrixFiveModern()
        {
            WeightedGraphList <string> graph = new WeightedGraphList <string>(true);

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

            PeakCodes peakCodes = new PeakCodes()
            {
                'a', 'b', 'c', 'd', 'e'
            };

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

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

            Assert.AreEqual(4, graph.PeakCount);
            Assert.AreEqual("a", graph.GetWeight(peakCodes['a'], peakCodes['b']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['a']));

            Assert.AreEqual("d", graph.GetWeight(peakCodes['d'], peakCodes['e']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['e'], peakCodes['d']));

            Assert.AreEqual("e", graph.GetWeight(peakCodes['e'], peakCodes['a']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['a'], peakCodes['e']));

            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.AreEqual("a", graph.GetWeight(peakCodes['a'], peakCodes['b']));
            Assert.IsFalse(graph.ContainsArc(peakCodes['b'], peakCodes['a']));

            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']));
        }