protected static void ContainsEdge_SourceTarget_ImmutableGraph_UndirectedGraph_Test(
            [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph,
            [NotNull, InstantHandle] Func <IImplicitUndirectedGraph <int, Edge <int> > > createGraph)
        {
            var edge1 = new Edge <int>(1, 2);
            var edge2 = new Edge <int>(1, 3);
            var edge3 = new Edge <int>(2, 2);

            IImplicitUndirectedGraph <int, Edge <int> > graph = createGraph();

            Assert.IsFalse(graph.ContainsEdge(1, 2));
            Assert.IsFalse(graph.ContainsEdge(2, 1));

            wrappedGraph.AddVerticesAndEdge(edge1);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(1, 2));
            Assert.IsTrue(graph.ContainsEdge(2, 1));

            wrappedGraph.AddVerticesAndEdge(edge2);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(1, 3));
            Assert.IsTrue(graph.ContainsEdge(3, 1));

            wrappedGraph.AddVerticesAndEdge(edge3);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(2, 2));

            // Vertices is not present in the graph
            Assert.IsFalse(graph.ContainsEdge(0, 4));
            Assert.IsFalse(graph.ContainsEdge(1, 4));
            Assert.IsFalse(graph.ContainsEdge(4, 1));
        }
        protected static void ContainsEdge_SourceTarget_ImmutableGraph_ReversedTest(
            IMutableVertexAndEdgeSet <int, Edge <int> > wrappedGraph,
            Func <IIncidenceGraph <int, SReversedEdge <int, Edge <int> > > > createGraph)
        {
            IIncidenceGraph <int, SReversedEdge <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, 2);

            Assert.IsFalse(graph.ContainsEdge(1, 2));
            Assert.IsFalse(graph.ContainsEdge(2, 1));

            wrappedGraph.AddVerticesAndEdge(edge1);
            graph = createGraph();
            Assert.IsFalse(graph.ContainsEdge(1, 2));
            Assert.IsTrue(graph.ContainsEdge(2, 1));

            wrappedGraph.AddVerticesAndEdge(edge2);
            graph = createGraph();
            Assert.IsFalse(graph.ContainsEdge(1, 3));
            Assert.IsTrue(graph.ContainsEdge(3, 1));

            wrappedGraph.AddVerticesAndEdge(edge3);
            graph = createGraph();
            Assert.IsTrue(graph.ContainsEdge(2, 2));

            // Vertices is not present in the graph
            Assert.IsFalse(graph.ContainsEdge(0, 4));
            Assert.IsFalse(graph.ContainsEdge(1, 4));
            Assert.IsFalse(graph.ContainsEdge(4, 1));
        }
 protected static void ContainsEdge_Test(
     [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > graph)
 {
     ContainsEdge_Test(
         graph,
         edge => graph.AddVerticesAndEdge(edge));
 }
Esempio n. 4
0
        protected static void AddVerticesAndEdge_Test(
            [NotNull] IMutableVertexAndEdgeSet <int, Edge <int> > graph)
        {
            int vertexAdded = 0;
            int edgeAdded   = 0;

            AssertEmptyGraph(graph);
            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            graph.VertexAdded += v =>
            {
                Assert.IsNotNull(v);
                ++vertexAdded;
            };
            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            graph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++edgeAdded;
            };

            // Edge 1
            var edge1 = new Edge <int>(1, 2);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge1));
            Assert.AreEqual(2, vertexAdded);
            Assert.AreEqual(1, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2 });
            AssertHasEdges(graph, new[] { edge1 });

            // Edge 2
            var edge2 = new Edge <int>(1, 3);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge2));
            Assert.AreEqual(3, vertexAdded);
            Assert.AreEqual(2, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2 });

            // Edge 3
            var edge3 = new Edge <int>(2, 3);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge3));
            Assert.AreEqual(3, vertexAdded);
            Assert.AreEqual(3, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3 });
        }
Esempio n. 5
0
 protected static void AddVerticesAndEdge_Throws_Test <TVertex, TEdge>(
     [NotNull] IMutableVertexAndEdgeSet <TVertex, TEdge> graph)
     where TEdge : class, IEdge <TVertex>
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     Assert.Throws <ArgumentNullException>(() => graph.AddVerticesAndEdge(null));
     AssertEmptyGraph(graph);
 }
Esempio n. 6
0
        protected static void AddVerticesAndEdge_Test(
            IMutableVertexAndEdgeSet <int, Edge <int> > graph)
        {
            int vertexAdded = 0;
            int edgeAdded   = 0;

            AssertEmptyGraph(graph);
            graph.VertexAdded += v =>
            {
                Assert.IsNotNull(v);
                ++vertexAdded;
            };
            graph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++edgeAdded;
            };

            // Edge 1
            var edge1 = new Edge <int>(1, 2);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge1));
            Assert.AreEqual(2, vertexAdded);
            Assert.AreEqual(1, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2 });
            AssertHasEdges(graph, new[] { edge1 });

            // Edge 2
            var edge2 = new Edge <int>(1, 3);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge2));
            Assert.AreEqual(3, vertexAdded);
            Assert.AreEqual(2, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2 });

            // Edge 3
            var edge3 = new Edge <int>(2, 3);

            Assert.IsTrue(graph.AddVerticesAndEdge(edge3));
            Assert.AreEqual(3, vertexAdded);
            Assert.AreEqual(3, edgeAdded);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3 });
        }
        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))));
        }