Esempio n. 1
0
        public void TryGetInEdges_Throws()
        {
            var wrappedGraph = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var graph        = new BidirectionalAdapterGraph <TestVertex, Edge <TestVertex> >(wrappedGraph);

            TryGetInEdges_Throws_Test(graph);
        }
Esempio n. 2
0
        public void AdapterLimits()
        {
            var edge12 = new Edge <int>(1, 2);
            var edge13 = new Edge <int>(1, 3);
            var edge23 = new Edge <int>(2, 3);
            var edge33 = new Edge <int>(3, 3);

            var wrappedGraph = new AdjacencyGraph <int, Edge <int> >();

            wrappedGraph.AddVerticesAndEdgeRange(new[] { edge12, edge13, edge23, edge33 });

            var graph = new BidirectionalAdapterGraph <int, Edge <int> >(wrappedGraph);

            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge12, edge13, edge23, edge33 });
            AssertHasOutEdges(graph, 3, new[] { edge33 });
            AssertHasInEdges(graph, 3, new[] { edge13, edge23, edge33 });

            var edge35 = new Edge <int>(3, 5);
            // Update wrapped graph => breaking change
            var edge43 = new Edge <int>(4, 3);

            wrappedGraph.AddVerticesAndEdgeRange(new[] { edge35, edge43 });

            AssertHasVertices(graph, new[] { 1, 2, 3, 4, 5 });                               // Vertices data are up to date
            AssertHasEdges(graph, new[] { edge12, edge13, edge23, edge33, edge35, edge43 }); // Edges data are up to date
            AssertHasOutEdges(graph, 3, new[] { edge33, edge35 });                           // Out data are up to date
            AssertHasInEdges(graph, 3, new[] { edge13, edge23, edge33 });                    // Missing edge43
        }
Esempio n. 3
0
        public void Degree_Throws()
        {
            var wrappedGraph = new AdjacencyGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();
            var graph        = new BidirectionalAdapterGraph <EquatableTestVertex, Edge <EquatableTestVertex> >(wrappedGraph);

            Degree_Throws_Test(graph);
        }
Esempio n. 4
0
        public void ContainsVertex_Throws()
        {
            var wrappedGraph = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var graph        = new BidirectionalAdapterGraph <TestVertex, Edge <TestVertex> >(wrappedGraph);

            ContainsVertex_Throws_Test(graph);
        }
        public void BinarySerialization_AdapterGraph([NotNull] AdjacencyGraph <int, EquatableEdge <int> > graph)
        {
            var bidirectionalAdapterGraph = new BidirectionalAdapterGraph <int, EquatableEdge <int> >(graph);
            BidirectionalAdapterGraph <int, EquatableEdge <int> > deserializedGraph =
                SerializeDeserialize <int, EquatableEdge <int>, BidirectionalAdapterGraph <int, EquatableEdge <int> > >(bidirectionalAdapterGraph);

            Assert.IsTrue(EquateGraphs.Equate(graph, deserializedGraph));
        }
Esempio n. 6
0
        public void BinarySerialization_AdapterGraph_Complex([NotNull] AdjacencyGraph <EquatableTestVertex, EquatableTestEdge> graph)
        {
            var bidirectionalAdapterGraph = new BidirectionalAdapterGraph <EquatableTestVertex, EquatableTestEdge>(graph);
            BidirectionalAdapterGraph <EquatableTestVertex, EquatableTestEdge> deserializedGraph =
                SerializeDeserialize <EquatableTestVertex, EquatableTestEdge, BidirectionalAdapterGraph <EquatableTestVertex, EquatableTestEdge> >(bidirectionalAdapterGraph);

            Assert.IsTrue(EquateGraphs.Equate(graph, deserializedGraph));
        }
Esempio n. 7
0
        public void InEdges_Throws()
        {
            var wrappedGraph1 = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var graph1        = new BidirectionalAdapterGraph <TestVertex, Edge <TestVertex> >(wrappedGraph1);

            InEdges_NullThrows_Test(graph1);

            var wrappedGraph2 = new AdjacencyGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();
            var graph2        = new BidirectionalAdapterGraph <EquatableTestVertex, Edge <EquatableTestVertex> >(wrappedGraph2);

            InEdges_Throws_Test(graph2);
        }
Esempio n. 8
0
        public void InEdge_Throws()
        {
            var wrappedGraph1 = new AdjacencyGraph <int, Edge <int> >();

            InEdge_Throws_ImmutableGraph_Test(
                wrappedGraph1,
                () => new BidirectionalAdapterGraph <int, Edge <int> >(wrappedGraph1));

            var wrappedGraph2 = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var graph2        = new BidirectionalAdapterGraph <TestVertex, Edge <TestVertex> >(wrappedGraph2);

            InEdge_NullThrows_Test(graph2);
        }
Esempio n. 9
0
        public void Construction()
        {
            var wrappedDirectedGraph = new AdjacencyGraph <int, Edge <int> >();

            var graph = new BidirectionalAdapterGraph <int, Edge <int> >(wrappedDirectedGraph);

            AssertGraphProperties(graph);
            AssertEmptyGraph(graph);

            // Graph has updated content but in-edges properties are broken
            // after updates of the wrapped graph
            wrappedDirectedGraph.AddVertexRange(new[] { 2, 3, 1 });

            AssertGraphProperties(graph);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertNoEdge(graph);

            graph = new BidirectionalAdapterGraph <int, Edge <int> >(wrappedDirectedGraph);
            AssertGraphProperties(graph);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertNoEdge(graph);

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

            // Graph has updated content but in-edges properties are broken
            // after updates of the wrapped graph
            wrappedDirectedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3, edge4 });

            AssertGraphProperties(graph);
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3, edge4 });

            graph = new BidirectionalAdapterGraph <int, Edge <int> >(wrappedDirectedGraph);
            AssertGraphProperties(graph);
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3, edge4 });

            wrappedDirectedGraph = new AdjacencyGraph <int, Edge <int> >(false);
            wrappedDirectedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge1, edge2, edge3, edge4 });
            graph = new BidirectionalAdapterGraph <int, Edge <int> >(wrappedDirectedGraph);
            AssertGraphProperties(graph, allowParallelEdges: false);
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3, edge4 });

            #region Local function

            void AssertGraphProperties <TVertex, TEdge>(
                BidirectionalAdapterGraph <TVertex, TEdge> g,
                bool isDirected         = true,
                bool allowParallelEdges = true)
                where TEdge : IEdge <TVertex>
            {
                Assert.AreEqual(isDirected, g.IsDirected);
                Assert.AreEqual(allowParallelEdges, g.AllowParallelEdges);
            }

            #endregion
        }