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 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 ShouldThrowInvalidWeightExceptionGivenNegativeEdgeWeight(char isourceNode, char idestinationNode, int iedgeWeight) { //Arrange var graphStub = MockRepository.GenerateStub <AbstractDiGraph <char> >(); graphStub.Stub(x => x.AllEdges) .Return(new List <Tuple <char, char, int> >() { new Tuple <char, char, int>(isourceNode, idestinationNode, iedgeWeight) }); var sut = new DijkstrasShortestPathAlgorithm <char>(); //Act + assert Assert.Throws <InvalidEdgeWeightException>( () => sut.GetShortestPath(graphStub, isourceNode, idestinationNode)); }