public void NoExceptionThrown_WhenVertexIsAccessibleFromRoot() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); Assert.DoesNotThrow(() => { double _ = algorithm.GetDistance(2); }); }
public void ExceptionThrown_WhenAlgorithmHasNotYetBeenComputed() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, SingleVerticesInGraph = new int[0], AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = false }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); Assert.Throws <InvalidOperationException>(() => algorithm.TryGetDistance(2, out _)); }
public void NoExceptionThrown_WhenVertexExistsButIsInaccessibleFromRoot() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, SingleVerticesInGraph = new[] { 3 }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); double _ = algorithm.GetDistance(3); }
public void DistanceReturned_WhenVertexIsAccessibleFromRoot() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); bool distanceFound = algorithm.TryGetDistance(2, out _); Assert.True(distanceFound, "Distance should have been found since the vertex is accessible from root."); }
public void NoDistanceFound_WhenVertexDoesNotExistInGraph() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); bool distanceFound = algorithm.TryGetDistance(3, out _); Assert.False(distanceFound, "No distance should have been found since the vertex does not exist."); }
public void ExceptionThrown_WhenTargetVertexIsNull() { var scenario = new ContractScenario <string> { EdgesInGraph = new[] { new Edge <string>("1", "2") }, SingleVerticesInGraph = new string[0], AccessibleVerticesFromRoot = new[] { "2" }, Root = "1", DoComputation = false }; IDistancesCollection <string> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => { double _ = algorithm.GetDistance(null); }); }
public void EmptyCollectionReturned_WhenAlgorithmHasNotYetBeenRun() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, SingleVerticesInGraph = new[] { 3 }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = false }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); IEnumerable <KeyValuePair <int, double> > distances = algorithm.GetDistances(); CollectionAssert.IsEmpty(distances); }
public void DistancesForAllVerticesInGraphReturnedWhenAlgorithmHasBeenRun() { var scenario = new ContractScenario <int> { EdgesInGraph = new[] { new Edge <int>(1, 2) }, SingleVerticesInGraph = new[] { 3 }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IDistancesCollection <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); IEnumerable <KeyValuePair <int, double> > distances = algorithm.GetDistances(); CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, distances.Select(pair => pair.Key)); }