Example #1
0
        public void ShortestPathFinishesWithinTimespan()
        {
            // This test is testing for possible deadlocks or inefficiencies
            // in the shortest path algorithm.

            var graph   = CreateTestGraph();
            var timeout = TimeSpan.FromMilliseconds(3000);

            ShortestPathLookup distanceDictionary = null;
            var thread = new Thread(() =>
            {
                distanceDictionary = GraphAlgorithms.ShortestPaths(graph, graph.GetVertexFromId(0));
            });

            thread.Start();
            thread.Join(timeout);

            Assert.That(distanceDictionary, Is.Not.Null);
        }
Example #2
0
        public void ShortestPathDoesntThrowIfGraphNotConnected()
        {
            var graph    = CreateTestGraph();
            var v1v2Edge = graph.Edges.Single(e => e.Vertex1Id == 0 && e.Vertex2Id == 1);

            graph.RemoveEdge(v1v2Edge);

            Assume.That(graph.GetVertexFromId(0).EdgeIds, Is.Empty);

            ShortestPathLookup shortestPathLookup = null;

            try
            {
                shortestPathLookup = GraphAlgorithms.ShortestPaths(graph, graph.GetVertexFromId(0));
            }
            catch (Exception)
            {
                Assert.Fail("GraphAlgorithm.ShortestPath should not throw exception for not connected test graph");
            }
            Assert.That(shortestPathLookup.PathLengthTo(graph.GetVertexFromId(1)), Is.EqualTo(double.PositiveInfinity));
        }