Esempio n. 1
0
        public void CalculateRightDistanceForFourNodes()
        {
            var vertex1 = new Vertex(1);
            var vertex2 = new Vertex(2);
            var vertex3 = new Vertex(3);
            var vertex4 = new Vertex(4);
            vertex1.Edges.Add(new Edge { To = vertex2, Length = 3 });
            vertex1.Edges.Add(new Edge { To = vertex3, Length = 4 });
            vertex1.Edges.Add(new Edge { To = vertex4, Length = 1 });
            vertex2.Edges.Add(new Edge { To = vertex4, Length = 5 });
            vertex4.Edges.Add(new Edge { To = vertex3, Length = 2 });
            var graph = new List<Vertex> { vertex1, vertex2, vertex3, vertex4 };

            var expected = new List<ShortestPath>
            { 
                new ShortestPath { From = vertex1, To = vertex1, Length = 0 },
                new ShortestPath { From = vertex1, To = vertex2, Length = 3 },
                new ShortestPath { From = vertex1, To = vertex3, Length = 3 },
                new ShortestPath { From = vertex1, To = vertex4, Length = 1 },
            };

            List<ShortestPath> actual = this.algorithm.FindShortestPaths(graph, sourceVertexId: 1);

            AssertionHelper.AssertAreEqual(expected, actual);
        }
        public void ParseTwoNodeInput()
        {
            var input = PrepareInput(@"1 2,5");

            var vertex1 = new Vertex(1);
            var vertex2 = new Vertex(2);
            vertex1.Edges.Add(new Edge { To = vertex2, Length = 5 });
            var expected = new List<Vertex> { vertex1, vertex2 };

            List<Vertex> actual = this.graphParser.Parse(input);

            AssertionHelper.AssertAreEqual(expected, actual);
        }
Esempio n. 3
0
        public void CalculateRightDistanceForThreeNodesOneNodeUnreacheble()
        {
            var vertex1 = new Vertex(1);
            var vertex2 = new Vertex(2);
            var vertex3 = new Vertex(3);
            vertex1.Edges.Add(new Edge { To = vertex2, Length = 5 });
            var graph = new List<Vertex> { vertex1, vertex2, vertex3 };

            var expected = new List<ShortestPath>
            { 
                new ShortestPath { From = vertex1, To = vertex1, Length = 0 },
                new ShortestPath { From = vertex1, To = vertex2, Length = 5 },
                new ShortestPath { From = vertex1, To = vertex3, Length = Algorithm.Infinity },
            };

            List<ShortestPath> actual = this.algorithm.FindShortestPaths(graph, sourceVertexId: 1);

            AssertionHelper.AssertAreEqual(expected, actual);
        }
        public void ParseFourNodeInput()
        {
            var input = PrepareInput(
@"1 2,5
2 3,6
4 3,4 2,7");

            var vertex1 = new Vertex(1);
            var vertex2 = new Vertex(2);
            var vertex3 = new Vertex(3);
            var vertex4 = new Vertex(4);
            vertex1.Edges.Add(new Edge { To = vertex2, Length = 5 });
            vertex2.Edges.Add(new Edge { To = vertex3, Length = 6 });
            vertex4.Edges.Add(new Edge { To = vertex3, Length = 4 });
            vertex4.Edges.Add(new Edge { To = vertex2, Length = 7 });
            var expected = new List<Vertex> { vertex1, vertex2, vertex3, vertex4 };

            List<Vertex> actual = this.graphParser.Parse(input);

            AssertionHelper.AssertAreEqual(expected, actual);
        }
        public void FilterDestinationVertices()
        {
            var expected = "3,1";

            var vertex1 = new Vertex(1);
            var vertex2 = new Vertex(2);
            var vertex3 = new Vertex(3);
            var vertex4 = new Vertex(4);
            var shortestPaths =
                    new List<ShortestPath> 
                        {
                            new ShortestPath { From = vertex1, To = vertex1, Length = 0 },
                            new ShortestPath { From = vertex1, To = vertex2, Length = 3 },
                            new ShortestPath { From = vertex1, To = vertex3, Length = 3 },
                            new ShortestPath { From = vertex1, To = vertex4, Length = 1 },
                        };
            var destinationVerticesIds = new List<int> { 2, 4 };

            var actual = OutputFormatter.Format(shortestPaths, destinationVerticesIds);

            Assert.AreEqual(expected, actual);
        }