public void ShouldCalculateShortestPathLength(string igraph, char isourceNode, char idestinationNode, int expectedShortedPathLength) { //Arrange var sut = new DijkstrasShortestPathAlgorithm <char>(); var graph = GraphLoaderHelper.LoadGraphFromString(igraph); //Act var result = sut.GetShortestPath(graph, isourceNode, idestinationNode).PathWeight; //Assert Assert.AreEqual(expectedShortedPathLength, result); }
public void ShouldReturnNullWhenNoPathExistsGivenSourceAndDestinationNode(string igraph, char isourceNode, char idestinationNode) { //Arrange var sut = new DijkstrasShortestPathAlgorithm <char>(); var graph = GraphLoaderHelper.LoadGraphFromString(igraph); //Act var result = sut.GetShortestPath(graph, isourceNode, idestinationNode); //Assert Assert.IsNull(result); }
public void ShouldCountAllCyclesGivenSourceNodeAndMaxPathWeight(string igraph, char isourceNode, int imaxWeight, int expectedCycleCount) { //Arrange var graph = GraphLoaderHelper.LoadGraphFromString(igraph); var sut = new CycleOperations <char>(); //Act var actual = sut.CountAllCycles(graph, isourceNode, imaxWeight); //Assert Assert.AreEqual(expectedCycleCount, actual); }
public void ShouldCountAllSimpleCyclesWhenGivenSourceNodeAndMaxStops(string igraph, char isourceNode, int imaxStops, int expectedCycleCount) { //Arrange var graph = GraphLoaderHelper.LoadGraphFromString(igraph); var sut = new CycleOperations <char>(); //Act var actual = sut.FindAllSimpleCycles(graph, isourceNode, imaxStops); //Assert Assert.AreEqual(expectedCycleCount, actual.Count); }
public void ShouldCountAllSimpleCycles(string igraph, int expectedCycleCount) { //Arrange var graph = GraphLoaderHelper.LoadGraphFromString(igraph); var sut = new CycleOperations <char>(); //Act var actual = sut.FindAllSimpleCycles(graph); //Assert Assert.AreEqual(expectedCycleCount, actual.Count); }
public void ShouldCountSimplePathsGivenSourceAndDestinationNode(string igraph, char isourceNode, char idestinationNode, int expectedNofPaths) { //Arrange var graph = GraphLoaderHelper.LoadGraphFromString(igraph); var sut = new PathOperations <Char>(); //Assert var actual = sut.FindAllSimplePaths(graph, isourceNode, idestinationNode); //Act Assert.AreEqual(expectedNofPaths, actual.Count); }
public void ShouldCountPathsWhenGivenSourceDestinationAndNumberOfStops(string igraph, char isourceNode, char idestinationNode, int inoOfStops, int expectedNoOfPaths) { //Arrange var graph = GraphLoaderHelper.LoadGraphFromString(igraph); var sut = new PathOperations <Char>(); //Assert var actual = sut.CountAllPaths(graph, isourceNode, idestinationNode, inoOfStops); //Atc Assert.AreEqual(expectedNoOfPaths, actual); }
public void ShouldTraverseAllEdges(string graph, string expected) { //Arrange var sut = new DepthFirstSearchAlgorithm <char>(); //Act var result = sut.TraverseGraph(GraphLoaderHelper.LoadGraphFromString(graph)); var actual = result.OrderBy(x => x.SourceNode) .ThenBy(x => x.DestinationNode) .ConvertDfsEdgeToString(); //Assert Assert.AreEqual(expected, actual); }
public void ShouldReturnDfsBackEdges(string graph, string expected) { var sut = new DepthFirstSearchAlgorithm <char>(); var result = sut.TraverseGraph(GraphLoaderHelper.LoadGraphFromString(graph)); var actual = result.Where(x => x.EdgeType == DepthFirstSearchEdgeType.BackEdge) .OrderBy(x => x.SourceNode) .ThenBy(x => x.DestinationNode) .ConvertDfsEdgeToString(); Assert.AreEqual(expected, actual); }