/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> protected void OutputGraph(Object sender, VertexEventArgs args) { IVertexColorizerAlgorithm algo = (IVertexColorizerAlgorithm)sender; m_Colors = algo.Colors; m_Algo.Write(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void TreeEdge(Object sender, EdgeEventArgs args) { IVertexColorizerAlgorithm algo = (IVertexColorizerAlgorithm)sender; m_Colors = algo.Colors; m_EdgeColors[args.Edge] = GraphColor.Black; m_Algo.Write(); }
public void ColorReturned_WhenVertexIsAccessibleFromRoot() { var scenario = new ContractScenario { EdgesInGraph = new[] { new Edge <int>(1, 2) }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IVertexColorizerAlgorithm <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); Assert.IsNotNull(algorithm.GetVertexColor(2)); }
public void ExceptionThrown_WhenVertexDoesNotExistInGraph() { var scenario = new ContractScenario { EdgesInGraph = new[] { new Edge <int>(1, 2) }, AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = true }; IVertexColorizerAlgorithm <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); Assert.Throws <VertexNotFoundException>(() => algorithm.GetVertexColor(3)); }
/// <summary> /// Extracts the color tables from the calling algorithm /// </summary> /// <param name="sender"></param> /// <param name="args"></param> protected void GetColors(Object sender, EdgeEventArgs args) { if (sender is IVertexColorizerAlgorithm) { IVertexColorizerAlgorithm algo = (IVertexColorizerAlgorithm)sender; m_Colors = algo.Colors; } if (sender is IEdgeColorizerAlgorithm) { IEdgeColorizerAlgorithm algo = (IEdgeColorizerAlgorithm)sender; m_EdgeColors = algo.EdgeColors; } else if (m_EdgeColors != null) { m_EdgeColors[args.Edge] = GraphColor.Black; } }
public void ExceptionThrown_WhenAlgorithmHasNotYetBeenComputed() { var scenario = new ContractScenario { EdgesInGraph = new[] { new Edge <int>(1, 2) }, SingleVerticesInGraph = new int[0], AccessibleVerticesFromRoot = new[] { 2 }, Root = 1, DoComputation = false }; IVertexColorizerAlgorithm <int> algorithm = CreateAlgorithmAndMaybeDoComputation(scenario); Type expectedExceptionType = GetExpectedExceptionType(); Assert.Throws(expectedExceptionType, () => algorithm.GetVertexColor(2)); #region Local function Type GetExpectedExceptionType() { switch (_testedAlgorithm) { case var _ when _testedAlgorithm == typeof(AStarShortestPathAlgorithm <,>): case var _ when _testedAlgorithm == typeof(BellmanFordShortestPathAlgorithm <,>): case var _ when _testedAlgorithm == typeof(DagShortestPathAlgorithm <,>): case var _ when _testedAlgorithm == typeof(DijkstraShortestPathAlgorithm <,>): case var _ when _testedAlgorithm == typeof(UndirectedDijkstraShortestPathAlgorithm <,>): return(typeof(NullReferenceException)); } return(typeof(VertexNotFoundException)); } #endregion }