コード例 #1
0
        public void TestContractingEdges()
        {
            var graph = new AmortizedGraph <Char>((oldEdge, newEdge) => oldEdge > newEdge);

            var a = new CharAmortizedNode('A');
            var b = new CharAmortizedNode('B');

            graph.AddNode(a);
            graph.AddNode(b);

            graph.AddUndirectedEdge(a, b, 10);
            Assert.AreEqual(10, a.Cost(b));

            graph.UpdateUndirectedEdge(a, b, 20);
            Assert.AreEqual(10, a.Cost(b));

            graph.UpdateUndirectedEdge(a, b, 6);
            Assert.AreEqual(8, a.Cost(b));
        }
コード例 #2
0
        public void TestEveryEdge()
        {
            var graph = new AmortizedGraph <Char>((oldEdge, newEdge) => true);

            var a = new CharAmortizedNode('A');
            var b = new CharAmortizedNode('B');

            graph.AddNode(a);
            graph.AddNode(b);

            graph.AddUndirectedEdge(a, b, 10);
            Assert.AreEqual(10, a.Cost(b));

            graph.UpdateUndirectedEdge(a, b, 20);
            Assert.AreEqual(15, a.Cost(b));

            graph.UpdateUndirectedEdge(a, b, 6);
            Assert.AreEqual(12, a.Cost(b));
        }