protected static void ContainsEdge_NullThrows_Test <TVertex, TEdge>(
     [NotNull] IEdgeSet <TVertex, TEdge> graph)
     where TEdge : class, IEdge <TVertex>
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
     Assert.Throws <ArgumentNullException>(() => graph.ContainsEdge(null));
 }
Beispiel #2
0
        protected static void ContainsEdge_Test(
            [NotNull] GraphData <int, Edge <int> > data,
            [NotNull] IEdgeSet <int, Edge <int> > graph)
        {
            data.CheckCalls(0);

            data.ShouldReturnValue = false;
            var edge12 = new Edge <int>(1, 2);
            var edge21 = new Edge <int>(2, 1);

            Assert.IsFalse(graph.ContainsEdge(edge12));
            data.CheckCalls(1);
            Assert.IsFalse(graph.ContainsEdge(edge21));
            data.CheckCalls(1);

            data.ShouldReturnValue = true;
            Assert.IsFalse(graph.ContainsEdge(edge12));
            data.CheckCalls(1);
            Assert.IsFalse(graph.ContainsEdge(edge21));
            data.CheckCalls(1);

            var edge13 = new Edge <int>(1, 3);

            data.ShouldReturnEdges = new[] { edge12, edge13, edge21 };
            Assert.IsTrue(graph.ContainsEdge(edge12));
            data.CheckCalls(1);
            Assert.IsTrue(graph.ContainsEdge(edge21));
            data.CheckCalls(1);

            var edge15 = new Edge <int>(1, 5);
            var edge51 = new Edge <int>(5, 1);
            var edge56 = new Edge <int>(5, 6);

            Assert.IsFalse(graph.ContainsEdge(edge15));
            Assert.IsFalse(graph.ContainsEdge(edge51));
            Assert.IsFalse(graph.ContainsEdge(edge56));
        }
        protected static void ContainsEdge_EquatableEdge_Test(
            [NotNull] IEdgeSet <int, EquatableEdge <int> > graph,
            [NotNull, InstantHandle] Action <EquatableEdge <int> > addVerticesAndEdge)
        {
            var edge1      = new EquatableEdge <int>(1, 2);
            var edge2      = new EquatableEdge <int>(1, 3);
            var edge3      = new EquatableEdge <int>(2, 1);
            var edge4      = new EquatableEdge <int>(2, 2);
            var otherEdge1 = new EquatableEdge <int>(1, 2);

            Assert.IsFalse(graph.ContainsEdge(edge1));
            Assert.IsFalse(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            addVerticesAndEdge(edge1);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsFalse(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            addVerticesAndEdge(edge2);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            addVerticesAndEdge(edge3);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            addVerticesAndEdge(edge4);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsTrue(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            addVerticesAndEdge(otherEdge1);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsTrue(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            // Both vertices not in graph
            Assert.IsFalse(graph.ContainsEdge(new EquatableEdge <int>(0, 10)));
            // Source not in graph
            Assert.IsFalse(graph.ContainsEdge(new EquatableEdge <int>(0, 1)));
            // Target not in graph
            Assert.IsFalse(graph.ContainsEdge(new EquatableEdge <int>(1, 0)));
        }
        protected static void ContainsEdge_ImmutableGraph_Test(
            [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph,
            [NotNull, InstantHandle] Func <IEdgeSet <int, Edge <int> > > createGraph)
        {
            IEdgeSet <int, Edge <int> > graph = createGraph();

            var edge1      = new Edge <int>(1, 2);
            var edge2      = new Edge <int>(1, 3);
            var edge3      = new Edge <int>(2, 1);
            var edge4      = new Edge <int>(2, 2);
            var otherEdge1 = new Edge <int>(1, 2);

            Assert.IsFalse(graph.ContainsEdge(edge1));
            Assert.IsFalse(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge1);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsFalse(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge2);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge3);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge4);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsTrue(graph.ContainsEdge(edge4));
            Assert.IsFalse(graph.ContainsEdge(otherEdge1));

            wrappedGraph.AddVerticesAndEdge(otherEdge1);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsTrue(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            // Both vertices not in graph
            Assert.IsFalse(graph.ContainsEdge(new Edge <int>(0, 10)));
            // Source not in graph
            Assert.IsFalse(graph.ContainsEdge(new Edge <int>(0, 1)));
            // Target not in graph
            Assert.IsFalse(graph.ContainsEdge(new Edge <int>(1, 0)));
        }
        protected static void ContainsEdge_EquatableEdge_ImmutableGraph_ReversedTest(
            IMutableVertexAndEdgeSet <int, EquatableEdge <int> > wrappedGraph,
            Func <IEdgeSet <int, SReversedEdge <int, EquatableEdge <int> > > > createGraph)
        {
            IEdgeSet <int, SReversedEdge <int, EquatableEdge <int> > > graph = createGraph();

            var edge1              = new EquatableEdge <int>(1, 2);
            var reversedEdge1      = new SReversedEdge <int, EquatableEdge <int> >(edge1);
            var edge2              = new EquatableEdge <int>(1, 3);
            var reversedEdge2      = new SReversedEdge <int, EquatableEdge <int> >(edge2);
            var edge3              = new EquatableEdge <int>(2, 1);
            var reversedEdge3      = new SReversedEdge <int, EquatableEdge <int> >(edge3);
            var edge4              = new EquatableEdge <int>(2, 2);
            var reversedEdge4      = new SReversedEdge <int, EquatableEdge <int> >(edge4);
            var otherEdge1         = new EquatableEdge <int>(1, 2);
            var reversedOtherEdge1 = new SReversedEdge <int, EquatableEdge <int> >(otherEdge1);

            Assert.IsFalse(graph.ContainsEdge(reversedEdge1));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge2));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge3));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge4));
            Assert.IsFalse(graph.ContainsEdge(reversedOtherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge1);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(reversedEdge1));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge2));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge3));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge4));
            Assert.IsTrue(graph.ContainsEdge(reversedOtherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge2);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(reversedEdge1));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge2));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge3));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge4));
            Assert.IsTrue(graph.ContainsEdge(reversedOtherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge3);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(reversedEdge1));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge2));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge3));
            Assert.IsFalse(graph.ContainsEdge(reversedEdge4));
            Assert.IsTrue(graph.ContainsEdge(reversedOtherEdge1));

            wrappedGraph.AddVerticesAndEdge(edge4);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(reversedEdge1));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge2));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge3));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge4));
            Assert.IsTrue(graph.ContainsEdge(reversedOtherEdge1));

            wrappedGraph.AddVerticesAndEdge(otherEdge1);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(reversedEdge1));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge2));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge3));
            Assert.IsTrue(graph.ContainsEdge(reversedEdge4));
            Assert.IsTrue(graph.ContainsEdge(reversedOtherEdge1));

            // Both vertices not in graph
            Assert.IsFalse(
                graph.ContainsEdge(
                    new SReversedEdge <int, EquatableEdge <int> >(
                        new EquatableEdge <int>(0, 10))));
            // Source not in graph
            Assert.IsFalse(
                graph.ContainsEdge(
                    new SReversedEdge <int, EquatableEdge <int> >(
                        new EquatableEdge <int>(0, 1))));
            // Target not in graph
            Assert.IsFalse(
                graph.ContainsEdge(
                    new SReversedEdge <int, EquatableEdge <int> >(
                        new EquatableEdge <int>(1, 0))));
        }