public void BinarySerialization_BidirectionalGraph([NotNull] BidirectionalGraph <int, EquatableEdge <int> > graph)
        {
            BidirectionalGraph <int, EquatableEdge <int> > deserializedGraph =
                SerializeDeserialize <int, EquatableEdge <int>, BidirectionalGraph <int, EquatableEdge <int> > >(graph);

            Assert.IsTrue(EquateGraphs.Equate(graph, deserializedGraph));

            var arrayGraph = new ArrayBidirectionalGraph <int, EquatableEdge <int> >(graph);
            ArrayBidirectionalGraph <int, EquatableEdge <int> > deserializedGraph2 =
                SerializeDeserialize <int, EquatableEdge <int>, ArrayBidirectionalGraph <int, EquatableEdge <int> > >(arrayGraph);

            Assert.IsTrue(EquateGraphs.Equate(arrayGraph, deserializedGraph2));

            var reversedGraph = new ReversedBidirectionalGraph <int, EquatableEdge <int> >(graph);
            ReversedBidirectionalGraph <int, EquatableEdge <int> > deserializedGraph3 =
                SerializeDeserialize <int, SReversedEdge <int, EquatableEdge <int> >, ReversedBidirectionalGraph <int, EquatableEdge <int> > >(reversedGraph);

            Assert.IsTrue(EquateGraphs.Equate(reversedGraph, deserializedGraph3));

            var undirectedBidirectionalGraph = new UndirectedBidirectionalGraph <int, EquatableEdge <int> >(graph);
            UndirectedBidirectionalGraph <int, EquatableEdge <int> > deserializedGraph4 =
                SerializeDeserialize <int, EquatableEdge <int>, UndirectedBidirectionalGraph <int, EquatableEdge <int> > >(undirectedBidirectionalGraph);

            Assert.IsTrue(EquateGraphs.Equate(undirectedBidirectionalGraph, deserializedGraph4));
        }
Beispiel #2
0
        public void TryGetInEdges_Throws()
        {
            var wrappedGraph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var graph        = new ArrayBidirectionalGraph <TestVertex, Edge <TestVertex> >(wrappedGraph);

            TryGetInEdges_Throws_Test(graph);
        }
Beispiel #3
0
        public void ContainsVertex_Throws()
        {
            var wrappedGraph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var graph        = new ArrayBidirectionalGraph <TestVertex, Edge <TestVertex> >(wrappedGraph);

            ContainsVertex_Throws_Test(graph);
        }
Beispiel #4
0
        public void Degree_Throws()
        {
            var wrappedGraph = new BidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();
            var graph        = new ArrayBidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >(wrappedGraph);

            Degree_Throws_Test(graph);
        }
Beispiel #5
0
        public void BinarySerialization_BidirectionalGraph_Complex([NotNull] BidirectionalGraph <EquatableTestVertex, EquatableTestEdge> graph)
        {
            BidirectionalGraph <EquatableTestVertex, EquatableTestEdge> deserializedGraph =
                SerializeDeserialize <EquatableTestVertex, EquatableTestEdge, BidirectionalGraph <EquatableTestVertex, EquatableTestEdge> >(graph);

            Assert.IsTrue(EquateGraphs.Equate(graph, deserializedGraph));

            var arrayGraph = new ArrayBidirectionalGraph <EquatableTestVertex, EquatableTestEdge>(graph);
            ArrayBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> deserializedGraph2 =
                SerializeDeserialize <EquatableTestVertex, EquatableTestEdge, ArrayBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> >(arrayGraph);

            Assert.IsTrue(EquateGraphs.Equate(arrayGraph, deserializedGraph2));

            var reversedGraph = new ReversedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge>(graph);
            ReversedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> deserializedGraph3 =
                SerializeDeserialize <EquatableTestVertex, SReversedEdge <EquatableTestVertex, EquatableTestEdge>, ReversedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> >(reversedGraph);

            Assert.IsTrue(EquateGraphs.Equate(reversedGraph, deserializedGraph3));

            var undirectedBidirectionalGraph = new UndirectedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge>(graph);
            UndirectedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> deserializedGraph4 =
                SerializeDeserialize <EquatableTestVertex, EquatableTestEdge, UndirectedBidirectionalGraph <EquatableTestVertex, EquatableTestEdge> >(undirectedBidirectionalGraph);

            Assert.IsTrue(EquateGraphs.Equate(undirectedBidirectionalGraph, deserializedGraph4));
        }
        public void GraphMLSerialization_BidirectionalGraph([NotNull] BidirectionalGraph <int, EquatableEdge <int> > graph)
        {
            AdjacencyGraph <int, EquatableEdge <int> > deserializedGraph =
                SerializeDeserialize <BidirectionalGraph <int, EquatableEdge <int> >, AdjacencyGraph <int, EquatableEdge <int> > >(graph);

            Assert.IsTrue(EquateGraphs.Equate(graph, deserializedGraph));

            var arrayGraph = new ArrayBidirectionalGraph <int, EquatableEdge <int> >(graph);
            AdjacencyGraph <int, EquatableEdge <int> > deserializedGraph2 =
                SerializeDeserialize <ArrayBidirectionalGraph <int, EquatableEdge <int> >, AdjacencyGraph <int, EquatableEdge <int> > >(arrayGraph);

            Assert.IsTrue(EquateGraphs.Equate(arrayGraph, deserializedGraph2));

            var reversedGraph = new ReversedBidirectionalGraph <int, EquatableEdge <int> >(graph);
            BidirectionalGraph <int, EquatableEdge <int> > deserializedGraph3 =
                SerializeDeserialize_Reversed <ReversedBidirectionalGraph <int, EquatableEdge <int> >, BidirectionalGraph <int, EquatableEdge <int> > >(reversedGraph);

            Assert.IsTrue(
                EquateGraphs.Equate(
                    graph,
                    deserializedGraph3,
                    EqualityComparer <int> .Default,
                    LambdaEqualityComparer <EquatableEdge <int> > .Create(
                        (edge1, edge2) => Equals(edge1.Source, edge2.Target) && Equals(edge1.Target, edge2.Source),
                        edge => edge.GetHashCode())));

            var undirectedBidirectionalGraph = new UndirectedBidirectionalGraph <int, EquatableEdge <int> >(graph);
            UndirectedGraph <int, EquatableEdge <int> > deserializedGraph4 =
                SerializeDeserialize <UndirectedBidirectionalGraph <int, EquatableEdge <int> >, UndirectedGraph <int, EquatableEdge <int> > >(undirectedBidirectionalGraph);

            Assert.IsTrue(EquateGraphs.Equate(undirectedBidirectionalGraph, deserializedGraph4));
        }
Beispiel #7
0
        public void ContainsEdge_Throws()
        {
            var wrappedGraph = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var graph        = new ArrayBidirectionalGraph <TestVertex, Edge <TestVertex> >(wrappedGraph);

            ContainsEdge_NullThrows_Test(graph);
            ContainsEdge_SourceTarget_Throws_Test(graph);
        }
Beispiel #8
0
        public void InEdges_Throws()
        {
            var wrappedGraph1 = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var graph1        = new ArrayBidirectionalGraph <TestVertex, Edge <TestVertex> >(wrappedGraph1);

            InEdges_NullThrows_Test(graph1);

            var wrappedGraph2 = new BidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();
            var graph2        = new ArrayBidirectionalGraph <EquatableTestVertex, Edge <EquatableTestVertex> >(wrappedGraph2);

            InEdges_Throws_Test(graph2);
        }
Beispiel #9
0
        public void InEdge_Throws()
        {
            var wrappedGraph1 = new BidirectionalGraph <int, Edge <int> >();

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

            var wrappedGraph2 = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();
            var graph2        = new ArrayBidirectionalGraph <TestVertex, Edge <TestVertex> >(wrappedGraph2);

            InEdge_NullThrows_Test(graph2);
        }
        private static void AssertSameProperties <TVertex, TEdge>(IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            ArrayBidirectionalGraph <TVertex, TEdge> bidirectionalGraph = graph.ToArrayBidirectionalGraph();

            Assert.AreEqual(graph.VertexCount, bidirectionalGraph.VertexCount);
            CollectionAssert.AreEqual(graph.Vertices, bidirectionalGraph.Vertices);

            Assert.AreEqual(graph.EdgeCount, bidirectionalGraph.EdgeCount);
            CollectionAssert.AreEqual(graph.Edges, bidirectionalGraph.Edges);

            foreach (TVertex vertex in graph.Vertices)
            {
                CollectionAssert.AreEqual(graph.OutEdges(vertex), bidirectionalGraph.OutEdges(vertex));
            }
        }
Beispiel #11
0
        public void Construction()
        {
            var wrappedGraph = new BidirectionalGraph <int, Edge <int> >();

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

            AssertGraphProperties(graph);
            AssertEmptyGraph(graph);

            wrappedGraph.AddVertexRange(new[] { 2, 3, 1 });
            graph = new ArrayBidirectionalGraph <int, Edge <int> >(wrappedGraph);
            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);

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

            wrappedGraph = new BidirectionalGraph <int, Edge <int> >(false);
            wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge1, edge2, edge3, edge4 });
            graph = new ArrayBidirectionalGraph <int, Edge <int> >(wrappedGraph);
            AssertGraphProperties(graph, false);
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3, edge4 });

            #region Local function

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

            #endregion
        }
Beispiel #12
0
        public void Clone()
        {
            var wrappedGraph = new BidirectionalGraph <int, Edge <int> >();

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

            AssertEmptyGraph(graph);

            var clonedGraph = graph.Clone();

            Assert.IsNotNull(clonedGraph);
            AssertEmptyGraph(clonedGraph);

            clonedGraph = (ArrayBidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertEmptyGraph(clonedGraph);

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

            wrappedGraph.AddVerticesAndEdgeRange(new[] { edge1, edge2, edge3 });

            graph = new ArrayBidirectionalGraph <int, Edge <int> >(wrappedGraph);
            AssertHasVertices(graph, new[] { 1, 2, 3 });
            AssertHasEdges(graph, new[] { edge1, edge2, edge3 });

            clonedGraph = graph.Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });

            clonedGraph = (ArrayBidirectionalGraph <int, Edge <int> >)((ICloneable)graph).Clone();
            Assert.IsNotNull(clonedGraph);
            AssertHasVertices(clonedGraph, new[] { 1, 2, 3 });
            AssertHasEdges(clonedGraph, new[] { edge1, edge2, edge3 });
        }