private void VerifyExpectedPaths( Vertex startVertex, Vertex endVertex, IList <Edge> edges, PathFinderFactory pathFinderFactory, ExpectedPath[] expectedShortestPaths ) { PathFinder pathFinder = pathFinderFactory.CreatePathFinder( edges, GraphEdgesValidationDesired.NO // do the validation one time instead of doing it for each pathFinderFactory ); IList <Path> actualShortestPaths = pathFinder.FindShortestPaths(startVertex, endVertex, 10); Assert.AreEqual(expectedShortestPaths.Length, actualShortestPaths.Count); string errorContext = pathFinderFactory.GetType().Name; for (int i = 0; i < expectedShortestPaths.Length; i++) { errorContext += " , i: " + i; ExpectedPath expectedPath = expectedShortestPaths[i]; Path actualPath = actualShortestPaths[i]; Assert.AreEqual(expectedPath.totalWeight, actualPath.TotalWeightForPath.WeightValue, SMALL_DELTA_VALUE_FOR_WEIGHT_COMPARISONS, errorContext); ExpectedEdge[] expectedEdgesForPath = expectedPath.expectedEdges; IList <Edge> actualEdgesForPath = actualPath.EdgesForPath; Assert.AreEqual(expectedEdgesForPath.Length, actualEdgesForPath.Count, errorContext); for (int j = 0; j < expectedEdgesForPath.Length; j++) { errorContext += " , j=" + j; ExpectedEdge expectedEdge = expectedEdgesForPath[j]; Edge actualEdge = actualEdgesForPath[j]; Assert.NotNull(actualEdge, errorContext); Assert.NotNull(actualEdge.EdgeWeight, errorContext); Assert.NotNull(actualEdge.StartVertex, errorContext); Assert.NotNull(actualEdge.EndVertex, errorContext); Assert.AreEqual(expectedEdge.weight, actualEdge.EdgeWeight.WeightValue, SMALL_DELTA_VALUE_FOR_WEIGHT_COMPARISONS, errorContext); Assert.AreEqual(expectedEdge.startVertexId, actualEdge.StartVertex.VertexId, errorContext); Assert.AreEqual(expectedEdge.endVertexId, actualEdge.EndVertex.VertexId, errorContext); Assert.AreEqual(expectedEdge.edgeId, actualEdge.EdgeId, errorContext); } } }
private ExpectedPath[] GetExpectedPaths() { ExpectedPath[] expectedPaths = new ExpectedPath[] { new ExpectedPath(13, new ExpectedEdge[] { new ExpectedEdge(GetEdgeId(A, B), A, B, WEIGHT_A_to_B), new ExpectedEdge(GetEdgeId(B, D), B, D, WEIGHT_B_to_D) }), new ExpectedPath(15, new ExpectedEdge[] { new ExpectedEdge(GetEdgeId(A, C), A, C, WEIGHT_A_to_C), new ExpectedEdge(GetEdgeId(C, D), C, D, WEIGHT_C_to_D) }), new ExpectedPath(21, new ExpectedEdge[] { new ExpectedEdge(GetEdgeId(A, B), A, B, WEIGHT_A_to_B), new ExpectedEdge(GetEdgeId(B, C), B, C, WEIGHT_B_to_C), new ExpectedEdge(GetEdgeId(C, D), C, D, WEIGHT_C_to_D) }) }; return(expectedPaths); }