Exemplo n.º 1
0
        public void ComputeWithoutRoot_Throws()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            ComputeWithoutRoot_Throws_Test(
                () => new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, edge => 1.0));

            var algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, edge => 1.0);

            Assert.Throws <InvalidOperationException>(algorithm.Compute);

            // Source (and target) vertex set but not to a vertex in the graph
            const int vertex1 = 1;

            algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, edge => 1.0);
            algorithm.SetRootVertex(vertex1);
            algorithm.SetTargetVertex(vertex1);
            Assert.Throws <VertexNotFoundException>(algorithm.Compute);

            const int vertex2 = 2;

            graph.AddVertex(vertex1);
            algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, edge => 1.0);
            algorithm.SetRootVertex(vertex1);
            algorithm.SetTargetVertex(vertex2);
            Assert.Throws <VertexNotFoundException>(algorithm.Compute);
        }
Exemplo n.º 2
0
        public void SetTargetVertex_Throws()
        {
            var graph     = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <TestVertex, Edge <TestVertex> >(graph, e => 1.0);

            // ReSharper disable once AssignNullToNotNullAttribute
            Assert.Throws <ArgumentNullException>(() => algorithm.SetTargetVertex(null));
        }
Exemplo n.º 3
0
        public void SetTargetVertex()
        {
            var graph     = new BidirectionalGraph <int, Edge <int> >();
            var algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, e => 1.0);

            const int vertex1 = 0;

            algorithm.SetTargetVertex(vertex1);
            algorithm.TryGetTargetVertex(out int target);
            Assert.AreEqual(vertex1, target);

            // Not changed
            algorithm.SetTargetVertex(vertex1);
            algorithm.TryGetTargetVertex(out target);
            Assert.AreEqual(vertex1, target);

            const int vertex2 = 1;

            algorithm.SetTargetVertex(vertex2);
            algorithm.TryGetTargetVertex(out target);
            Assert.AreEqual(vertex2, target);
        }
Exemplo n.º 4
0
        public void TryGetTargetVertex()
        {
            var graph     = new BidirectionalGraph <int, Edge <int> >();
            var algorithm = new HoffmanPavleyRankedShortestPathAlgorithm <int, Edge <int> >(graph, e => 1.0);

            Assert.IsFalse(algorithm.TryGetTargetVertex(out _));

            const int vertex = 0;

            algorithm.SetTargetVertex(vertex);
            Assert.IsTrue(algorithm.TryGetTargetVertex(out int target));
            AssertEqual(vertex, target);
        }