protected static void TryGetInEdges_Test( [NotNull] IBidirectionalIncidenceGraph <int, Edge <int> > graph, [NotNull, InstantHandle] Action <IEnumerable <Edge <int> > > addVerticesAndEdgeRange) { var edge1 = new Edge <int>(1, 2); var edge2 = new Edge <int>(1, 2); var edge3 = new Edge <int>(1, 3); var edge4 = new Edge <int>(2, 2); var edge5 = new Edge <int>(2, 4); var edge6 = new Edge <int>(3, 1); var edge7 = new Edge <int>(5, 3); addVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6, edge7 }); Assert.IsFalse(graph.TryGetInEdges(0, out _)); Assert.IsTrue(graph.TryGetInEdges(5, out IEnumerable <Edge <int> > gotEdges)); CollectionAssert.IsEmpty(gotEdges); Assert.IsTrue(graph.TryGetInEdges(4, out gotEdges)); CollectionAssert.AreEqual(new[] { edge5 }, gotEdges); Assert.IsTrue(graph.TryGetInEdges(2, out gotEdges)); CollectionAssert.AreEqual(new[] { edge1, edge2, edge4 }, gotEdges); }
protected static void TryGetInEdges_ImmutableGraph_ReversedTest( [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph, [NotNull, InstantHandle] Func <IBidirectionalIncidenceGraph <int, SReversedEdge <int, Edge <int> > > > createGraph) { var edge1 = new Edge <int>(1, 2); var edge2 = new Edge <int>(1, 2); var edge3 = new Edge <int>(1, 3); var edge4 = new Edge <int>(1, 1); var edge5 = new Edge <int>(2, 4); var edge6 = new Edge <int>(3, 1); var edge7 = new Edge <int>(4, 5); wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6, edge7 }); IBidirectionalIncidenceGraph <int, SReversedEdge <int, Edge <int> > > graph = createGraph(); Assert.IsFalse(graph.TryGetInEdges(0, out _)); Assert.IsTrue(graph.TryGetInEdges(5, out IEnumerable <SReversedEdge <int, Edge <int> > > gotEdges)); CollectionAssert.IsEmpty(gotEdges); Assert.IsTrue(graph.TryGetInEdges(4, out gotEdges)); AssertSameReversedEdges(new[] { edge7 }, gotEdges); Assert.IsTrue(graph.TryGetInEdges(1, out gotEdges)); AssertSameReversedEdges(new[] { edge1, edge2, edge3, edge4 }, gotEdges); }
protected static void TryGetInEdges_ImmutableGraph_Test( IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph, Func <IBidirectionalIncidenceGraph <int, Edge <int> > > createGraph) { var edge1 = new Edge <int>(1, 2); var edge2 = new Edge <int>(1, 2); var edge3 = new Edge <int>(1, 3); var edge4 = new Edge <int>(2, 2); var edge5 = new Edge <int>(2, 4); var edge6 = new Edge <int>(3, 1); var edge7 = new Edge <int>(5, 3); wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6, edge7 }); IBidirectionalIncidenceGraph <int, Edge <int> > graph = createGraph(); Assert.IsFalse(graph.TryGetInEdges(0, out _)); Assert.IsTrue(graph.TryGetInEdges(5, out IEnumerable <Edge <int> > gotEdges)); CollectionAssert.IsEmpty(gotEdges); Assert.IsTrue(graph.TryGetInEdges(4, out gotEdges)); CollectionAssert.AreEqual(new[] { edge5 }, gotEdges); Assert.IsTrue(graph.TryGetInEdges(2, out gotEdges)); CollectionAssert.AreEqual(new[] { edge1, edge2, edge4 }, gotEdges); }
protected static void TryGetInEdges_Throws_Test <TVertex, TEdge>( [NotNull] IBidirectionalIncidenceGraph <TVertex, TEdge> graph) where TVertex : class where TEdge : IEdge <TVertex> { // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => graph.TryGetInEdges(null, out _)); }
protected static void TryGetInEdges_Test( [NotNull] GraphData <int, Edge <int> > data, [NotNull] IBidirectionalIncidenceGraph <int, Edge <int> > graph) { data.CheckCalls(0); data.ShouldReturnValue = false; Assert.IsFalse(graph.TryGetInEdges(1, out _)); data.CheckCalls(1); data.ShouldReturnValue = true; Assert.IsTrue(graph.TryGetInEdges(1, out IEnumerable <Edge <int> > edges)); CollectionAssert.IsEmpty(edges); data.CheckCalls(1); data.ShouldReturnEdges = new[] { new Edge <int>(4, 1), new Edge <int>(2, 1) }; Assert.IsTrue(graph.TryGetInEdges(1, out edges)); CollectionAssert.AreEqual(data.ShouldReturnEdges, edges); data.CheckCalls(1); }