protected static void TryGetEdge_Throws_Test <TVertex, TEdge>( [NotNull] IIncidenceGraph <TVertex, TEdge> graph) where TVertex : class, new() where TEdge : IEdge <TVertex> { // ReSharper disable AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => graph.TryGetEdge(null, new TVertex(), out _)); Assert.Throws <ArgumentNullException>(() => graph.TryGetEdge(new TVertex(), null, out _)); Assert.Throws <ArgumentNullException>(() => graph.TryGetEdge(null, null, out _)); // ReSharper restore AssignNullToNotNullAttribute }
protected static void TryGetEdge_Test( [NotNull] GraphData <int, Edge <int> > data, [NotNull] IIncidenceGraph <int, Edge <int> > graph) { ContainsEdge_SourceTarget_GenericTest( data, (source, target) => graph.TryGetEdge(source, target, out _)); }
protected static void TryGetEdge_ImmutableGraph_Test( [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph, [NotNull, InstantHandle] Func <IIncidenceGraph <int, SEquatableEdge <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); wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6 }); IIncidenceGraph <int, SEquatableEdge <int> > graph = createGraph(); Assert.IsFalse(graph.TryGetEdge(0, 10, out _)); Assert.IsFalse(graph.TryGetEdge(0, 1, out _)); Assert.IsTrue(graph.TryGetEdge(2, 4, out SEquatableEdge <int> gotEdge)); Assert.AreEqual(new SEquatableEdge <int>(2, 4), gotEdge); Assert.IsTrue(graph.TryGetEdge(2, 2, out gotEdge)); Assert.AreEqual(new SEquatableEdge <int>(2, 2), gotEdge); Assert.IsTrue(graph.TryGetEdge(1, 2, out gotEdge)); Assert.AreEqual(new SEquatableEdge <int>(1, 2), gotEdge); Assert.IsFalse(graph.TryGetEdge(2, 1, out _)); }
protected static void TryGetEdge_Test( [NotNull] IIncidenceGraph <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); addVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6 }); Assert.IsFalse(graph.TryGetEdge(0, 10, out _)); Assert.IsFalse(graph.TryGetEdge(0, 1, out _)); Assert.IsTrue(graph.TryGetEdge(2, 4, out Edge <int> gotEdge)); Assert.AreSame(edge5, gotEdge); Assert.IsTrue(graph.TryGetEdge(2, 2, out gotEdge)); Assert.AreSame(edge4, gotEdge); Assert.IsTrue(graph.TryGetEdge(1, 2, out gotEdge)); Assert.AreSame(edge1, gotEdge); Assert.IsFalse(graph.TryGetEdge(2, 1, out _)); }
protected static void TryGetEdge_ImmutableGraph_ReversedTest( IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph, Func <IIncidenceGraph <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>(2, 2); var edge5 = new Edge <int>(2, 4); var edge6 = new Edge <int>(3, 1); wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4, edge5, edge6 }); IIncidenceGraph <int, SReversedEdge <int, Edge <int> > > graph = createGraph(); Assert.IsFalse(graph.TryGetEdge(0, 10, out _)); Assert.IsFalse(graph.TryGetEdge(0, 1, out _)); Assert.IsTrue(graph.TryGetEdge(4, 2, out SReversedEdge <int, Edge <int> > gotEdge)); AssertSameReversedEdge(edge5, gotEdge); Assert.IsTrue(graph.TryGetEdge(2, 2, out gotEdge)); AssertSameReversedEdge(edge4, gotEdge); Assert.IsTrue(graph.TryGetEdge(2, 1, out gotEdge)); AssertSameReversedEdge(edge1, gotEdge); Assert.IsFalse(graph.TryGetEdge(1, 2, out _)); }