public void Predicate_Throws() { var graph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >(); var predicate = new IsolatedVertexPredicate <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 }
public void Predicate <TGraph>([NotNull] TGraph graph) where TGraph : IBidirectionalGraph <int, Edge <int> > , IMutableVertexSet <int> , IMutableEdgeListGraph <int, Edge <int> > { var predicate = new IsolatedVertexPredicate <int, Edge <int> >(graph); graph.AddVertex(1); graph.AddVertex(2); Assert.IsTrue(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); graph.AddVertex(3); var edge13 = new Edge <int>(1, 3); graph.AddEdge(edge13); Assert.IsFalse(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsFalse(predicate.Test(3)); var edge12 = new Edge <int>(1, 2); graph.AddEdge(edge12); Assert.IsFalse(predicate.Test(1)); Assert.IsFalse(predicate.Test(2)); Assert.IsFalse(predicate.Test(3)); var edge23 = new Edge <int>(2, 3); graph.AddEdge(edge23); Assert.IsFalse(predicate.Test(1)); Assert.IsFalse(predicate.Test(2)); Assert.IsFalse(predicate.Test(3)); graph.RemoveEdge(edge23); Assert.IsFalse(predicate.Test(1)); Assert.IsFalse(predicate.Test(2)); Assert.IsFalse(predicate.Test(3)); graph.RemoveEdge(edge12); Assert.IsFalse(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsFalse(predicate.Test(3)); graph.RemoveEdge(edge13); Assert.IsTrue(predicate.Test(1)); Assert.IsTrue(predicate.Test(2)); Assert.IsTrue(predicate.Test(3)); }
public void removeIsolatedVertices() { var graph = new BidirectionalGraph <int, IEdge <int> >(); graph.AddVertex(1); var edge = new EquatableEdge <int>(2, 3); graph.AddVerticesAndEdge(edge); var predicate = new IsolatedVertexPredicate <int, IEdge <int> >(graph); graph.RemoveVertexIf(predicate.Test); Assert.IsTrue(graph.ContainsVertex(2)); Assert.IsTrue(graph.ContainsEdge(edge)); Assert.IsFalse(graph.ContainsVertex(1)); }