public void Predicate_Throws() { var graph = new AdjacencyGraph <TestVertex, Edge <TestVertex> >(); var predicate = new SinkVertexPredicate <TestVertex, Edge <TestVertex> >(graph); // ReSharper disable ReturnValueOfPureMethodIsNotUsed Assert.Throws <VertexNotFoundException>(() => predicate.Test(new TestVertex("1"))); // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => predicate.Test(null)); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
/// <summary> /// Returns an enumerable collection of the leaf vertices of the graph /// </summary> /// <param name="g">graph to visit</param> /// <returns>enumerable of leaf vertices</returns> /// <remarks> /// <para> /// Thread safe. /// </para> /// </remarks> public static IVertexEnumerable Sinks( IVertexListGraph g ) { SinkVertexPredicate leaf = new SinkVertexPredicate(g); return(new FilteredVertexEnumerable( g.Vertices, leaf )); }
public void Predicate <TGraph>([NotNull] TGraph graph) where TGraph : IIncidenceGraph <int, Edge <int> > , IMutableVertexSet <int> , IMutableEdgeListGraph <int, Edge <int> > { var predicate = new SinkVertexPredicate <int, Edge <int> >(graph); graph.AddVertex(1); graph.AddVertex(2); Assert.IsTrue(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); graph.AddVertex(3); graph.AddEdge(new Edge <int>(1, 3)); Assert.IsFalse(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsTrue(predicate.Test(3)); graph.AddEdge(new Edge <int>(1, 2)); Assert.IsFalse(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsTrue(predicate.Test(3)); var edge23 = new Edge <int>(2, 3); graph.AddEdge(edge23); Assert.IsFalse(predicate.Test(1)); Assert.IsFalse(predicate.Test(2)); Assert.IsTrue(predicate.Test(3)); graph.RemoveEdge(edge23); Assert.IsFalse(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsTrue(predicate.Test(3)); }