Beispiel #1
0
        private void FindsCorrectForFourVertices(IFastestRouteFinder algorithm, int start, int target, int expectedDistance, int[] expectedRoute)
        {
            // Arrange

            /* 0 --- 1 --- 3
             * |     |     |
             *  ---- 2 ----
             */
            var graph = new int[, ]
            {
                { 0, 5, 2, -1 },
                { 5, 0, 1, 6 },
                { 2, 1, 0, 8 },
                { -1, 6, 8, 0 }
            };

            // Act
            var result = algorithm.Find(graph, start, target);

            // Assert
            result.Distance.Should().Be(expectedDistance);
            result.Route.Should().BeEquivalentTo(expectedRoute);
        }
Beispiel #2
0
        private void FindsCorrectForEightVertices(IFastestRouteFinder algorithm, int start, int target, int expectedDistance, int[] expectedRoute)
        {
            // Arrange
            var graph = new int[, ]
            {
                { 0, 2, 3, -1, -1, -1, -1, -1 },
                { 2, 0, -1, 7, -1, -1, -1, -1 },
                { 3, -1, 0, 9, 4, -1, -1, -1 },
                { -1, 7, 9, 0, -1, 6, 5, -1 },
                { -1, -1, 4, -1, 0, 7, -1, 9 },
                { -1, -1, -1, 6, 7, 0, 10, 12 },
                { -1, -1, -1, 5, -1, 10, 0, -1 },
                { -1, -1, -1, -1, 9, 12, -1, 0 }
            };

            var dijkstra = new DijkstraRouteFinder();

            // Act
            var result = algorithm.Find(graph, start, target);

            // Assert
            result.Distance.Should().Be(expectedDistance);
            result.Route.Should().BeEquivalentTo(expectedRoute);
        }