コード例 #1
0
        public void GivenSingleSourceSingleDestinationWhenFindMaximumFlowThenWorksFine()
        {
            // arrange
            var source      = new SimpleNode("START");
            var destination = new SimpleNode("DESTINATION");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(source, destination, 1),
            };

            // act & assert
            Assert.DoesNotThrow(() => arcs.FindMaximumFlow());
        }
コード例 #2
0
        public void GivenCycledLoopsWhenTryToFindMaximumFlowThenThrowError()
        {
            // arrange
            var a = new SimpleNode("A");
            var b = new SimpleNode("B");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(a, b, 1),
                new SimpleArcWithFlow <SimpleNode>(b, a, 1),
            };

            // act & assert
            Assert.Throws <ArgumentException>(() => arcs.FindMaximumFlow());
        }
コード例 #3
0
        public void GivenTwoDestinationsWhenTryToFindMaximumFlowThenThrowError()
        {
            // arrange
            var source       = new SimpleNode("START");
            var destination1 = new SimpleNode("DESTINATION_1");
            var destination2 = new SimpleNode("DESTINATION_2");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(source, destination1, 1),
                new SimpleArcWithFlow <SimpleNode>(source, destination2, 1),
            };

            // act & assert
            Assert.Throws <ArgumentException>(() => arcs.FindMaximumFlow());
        }
コード例 #4
0
        public void GivenOneArcWhenFindMaximumFlowThenReturnItsFlow()
        {
            // arrange
            var source      = new SimpleNode("START");
            var destination = new SimpleNode("DESTINATION");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(source, destination, 123),
            };

            // act
            double maxFlow = arcs.FindMaximumFlow(source, destination);

            // assert
            Assert.AreEqual(123, maxFlow);
        }
コード例 #5
0
        public void GivenNoArcsFromStartWhenFindShortestPathsThenReturnEmpty()
        {
            // arrange
            var start = new SimpleNode("START");
            var a     = new SimpleNode("A");
            var b     = new SimpleNode("B");

            var arcs = new IArcWithLength <SimpleNode>[]
            {
                new SimpleArcWithLength <SimpleNode>(a, b, 10),
            };

            // act
            var foundPaths = arcs.FindShortestPaths(start);

            // assert
            Assert.AreEqual(0, foundPaths.Count);
        }
コード例 #6
0
        public void GivenParallelArcsWhenFindMaximumFlowThenReturnTheirSummary()
        {
            // arrange
            var source      = new SimpleNode("START");
            var destination = new SimpleNode("DESTINATION");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(source, destination, 123),
                new SimpleArcWithFlow <SimpleNode>(source, destination, 456),
                new SimpleArcWithFlow <SimpleNode>(source, destination, 789),
            };

            // act
            double maxFlow = arcs.FindMaximumFlow(source, destination);

            // assert
            Assert.AreEqual(123 + 456 + 789, maxFlow);
        }
コード例 #7
0
        public void GivenLinearChainWhenFindMaximumFlowThenReturnMinimumFlow()
        {
            // arrange
            var a = new SimpleNode("A");
            var b = new SimpleNode("B");
            var c = new SimpleNode("C");
            var d = new SimpleNode("D");

            var arcs = new List <IArcWithFlow <SimpleNode> >
            {
                new SimpleArcWithFlow <SimpleNode>(a, b, 567),
                new SimpleArcWithFlow <SimpleNode>(b, c, 123),
                new SimpleArcWithFlow <SimpleNode>(c, d, 234),
            };

            // act
            double maxFlow = arcs.FindMaximumFlow(a, d);

            // assert
            Assert.AreEqual(123, maxFlow);
        }
コード例 #8
0
        public void GivenChainWhenFindShortestPathsThenReturnSimple()
        {
            // arrange
            var start = new SimpleNode("START");
            var a     = new SimpleNode("A");
            var b     = new SimpleNode("B");
            var c     = new SimpleNode("C");

            var arcs = new IArcWithLength <SimpleNode>[]
            {
                new SimpleArcWithLength <SimpleNode>(start, a, 1),
                new SimpleArcWithLength <SimpleNode>(a, b, 2),
                new SimpleArcWithLength <SimpleNode>(b, c, 3),
            };

            // act
            var foundPaths = arcs.FindShortestPaths(start);

            // assert
            Assert.AreEqual(3, foundPaths.Count);
            Assert.AreEqual(1, foundPaths.First(p => p.To == a).Lenght);
            Assert.AreEqual(3, foundPaths.First(p => p.To == b).Lenght);
            Assert.AreEqual(6, foundPaths.First(p => p.To == c).Lenght);
        }
コード例 #9
0
ファイル: HuffmanTest.cs プロジェクト: CourageAndrey/AI
 private static ulong getWeight(SimpleNode item)
 {
     return(item.Weight);
 }