public EdgeListGraph<int, Edge<int>> ParralelEdges()
 {
     EdgeListGraph<int, Edge<int>> g = new EdgeListGraph<int, Edge<int>>();
     g.AddEdge(new Edge<int>(0, 1));
     g.AddEdge(new Edge<int>(0, 1));
     return g;
 }
 public EdgeListGraph<int, Edge<int>> TwoEdges()
 {
     EdgeListGraph<int, Edge<int>> g = new EdgeListGraph<int, Edge<int>>();
     g.AddEdge(new Edge<int>(0, 1));
     g.AddEdge(new Edge<int>(2, 3));
     return g;
 }
 public EdgeListGraph<int, Edge<int>> Loop()
 {
     EdgeListGraph<int, Edge<int>> g = new EdgeListGraph<int, Edge<int>>();
     g.AddEdge(new Edge<int>(0, 1));
     g.AddEdge(new Edge<int>(1, 0));
     return g;
 }
Exemplo n.º 4
0
        public void RemoveEdge_EquatableEdge()
        {
            var graph = new EdgeListGraph <int, EquatableEdge <int> >();

            RemoveEdge_EquatableEdge_EdgesOnly_Test(graph);
        }
Exemplo n.º 5
0
        public void ContainsEdge_Throws()
        {
            var graph = new EdgeListGraph <TestVertex, Edge <TestVertex> >();

            ContainsEdge_NullThrows_Test(graph);
        }
Exemplo n.º 6
0
        public void ContainsEdge_EquatableEdge()
        {
            var graph = new EdgeListGraph <int, EquatableEdge <int> >();

            ContainsEdge_EquatableEdge_EdgesOnly_Test(graph);
        }
Exemplo n.º 7
0
        public void ContainsVertex_EquatableVertex()
        {
            var graph = new EdgeListGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();

            ContainsVertex_EquatableVertex_OnlyEdges_Test(graph);
        }
Exemplo n.º 8
0
        public void AddVerticesAndEdgeRange_Throws()
        {
            var graph = new EdgeListGraph <int, Edge <int> >();

            AddVerticesAndEdgeRange_Throws_EdgesOnly_Test(graph);
        }
Exemplo n.º 9
0
        public void AddEdgeRange()
        {
            var graph = new EdgeListGraph <int, Edge <int> >(true, false);

            AddEdgeRange_EdgesOnly_Test(graph);
        }
 public EdgeListGraph<int, Edge<int>> OneEdge()
 {
     EdgeListGraph<int, Edge<int>> g = new EdgeListGraph<int, Edge<int>>();
     g.AddEdge(new Edge<int>(0,1));
     return g;
 }
Exemplo n.º 11
0
        protected static void AddEdge_ParallelEdges_EdgesOnly_Test(
            [NotNull] EdgeListGraph <int, Edge <int> > directedGraph,
            [NotNull] EdgeListGraph <int, Edge <int> > undirectedGraph,
            [NotNull, InstantHandle] Func <
                EdgeListGraph <int, Edge <int> >,
                Edge <int>,
                bool> addEdge)
        {
            if (!directedGraph.IsDirected && directedGraph.AllowParallelEdges)
            {
                throw new InvalidOperationException("Graph must be directed and allow parallel edges.");
            }
            if (undirectedGraph.IsDirected && undirectedGraph.AllowParallelEdges)
            {
                throw new InvalidOperationException("Graph must be undirected and allow parallel edges.");
            }

            int directedEdgeAdded   = 0;
            int undirectedEdgeAdded = 0;

            AssertNoEdge(directedGraph);
            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            directedGraph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++directedEdgeAdded;
            };

            AssertNoEdge(undirectedGraph);
            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            undirectedGraph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++undirectedEdgeAdded;
            };

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

            Assert.IsTrue(addEdge(directedGraph, edge1));
            Assert.AreEqual(1, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1 });

            Assert.IsTrue(addEdge(undirectedGraph, edge1));
            Assert.AreEqual(1, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1 });

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

            Assert.IsTrue(addEdge(directedGraph, edge2));
            Assert.AreEqual(2, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge2 });

            Assert.IsTrue(addEdge(undirectedGraph, edge2));
            Assert.AreEqual(2, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1, edge2 });

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

            Assert.IsTrue(addEdge(directedGraph, edge3));
            Assert.AreEqual(3, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge2, edge3 });

            Assert.IsTrue(addEdge(undirectedGraph, edge3));
            Assert.AreEqual(3, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1, edge2, edge3 });

            // Edge 1 bis
            Assert.IsFalse(addEdge(directedGraph, edge1));
            Assert.AreEqual(3, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge2, edge3 });

            Assert.IsFalse(addEdge(undirectedGraph, edge1));
            Assert.AreEqual(3, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1, edge2, edge3 });

            // Edge 4 self edge
            var edge4 = new Edge <int>(2, 2);

            Assert.IsTrue(addEdge(directedGraph, edge4));
            Assert.AreEqual(4, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge2, edge3, edge4 });

            Assert.IsTrue(addEdge(undirectedGraph, edge4));
            Assert.AreEqual(4, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1, edge2, edge3, edge4 });
        }
Exemplo n.º 12
0
        protected static void AddEdge_NoParallelEdges_EquatableEdge_EdgesOnly_Test(
            [NotNull] EdgeListGraph <int, EquatableEdge <int> > directedGraph,
            [NotNull] EdgeListGraph <int, EquatableEdge <int> > undirectedGraph,
            [NotNull, InstantHandle] Func <
                EdgeListGraph <int, EquatableEdge <int> >,
                EquatableEdge <int>,
                bool> addEdge)
        {
            if (!directedGraph.IsDirected && !directedGraph.AllowParallelEdges)
            {
                throw new InvalidOperationException("Graph must be directed and not allow parallel edges.");
            }
            if (undirectedGraph.IsDirected && !undirectedGraph.AllowParallelEdges)
            {
                throw new InvalidOperationException("Graph must be undirected and not allow parallel edges.");
            }

            int directedEdgeAdded   = 0;
            int undirectedEdgeAdded = 0;

            AssertNoEdge(directedGraph);
            directedGraph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++directedEdgeAdded;
            };

            AssertNoEdge(undirectedGraph);
            undirectedGraph.EdgeAdded += e =>
            {
                Assert.IsNotNull(e);
                ++undirectedEdgeAdded;
            };

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

            Assert.IsTrue(addEdge(directedGraph, edge1));
            Assert.AreEqual(1, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1 });

            Assert.IsTrue(addEdge(undirectedGraph, edge1));
            Assert.AreEqual(1, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1 });

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

            Assert.IsFalse(addEdge(directedGraph, edge2));
            Assert.AreEqual(1, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1 });

            Assert.IsFalse(addEdge(undirectedGraph, edge2));
            Assert.AreEqual(1, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1 });

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

            Assert.IsTrue(addEdge(directedGraph, edge3));
            Assert.AreEqual(2, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge3 });

            Assert.IsFalse(addEdge(undirectedGraph, edge3));
            Assert.AreEqual(1, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1 });

            // Edge 1 bis
            Assert.IsFalse(addEdge(directedGraph, edge1));
            Assert.AreEqual(2, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge3 });

            Assert.IsFalse(addEdge(undirectedGraph, edge1));
            Assert.AreEqual(1, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1 });

            // Edge 4 self edge
            var edge4 = new EquatableEdge <int>(2, 2);

            Assert.IsTrue(addEdge(directedGraph, edge4));
            Assert.AreEqual(3, directedEdgeAdded);
            AssertHasEdges(directedGraph, new[] { edge1, edge3, edge4 });

            Assert.IsTrue(addEdge(undirectedGraph, edge4));
            Assert.AreEqual(2, undirectedEdgeAdded);
            AssertHasEdges(undirectedGraph, new[] { edge1, edge4 });
        }
Exemplo n.º 13
0
        public void RemoveEdgeIf_Throws()
        {
            var graph = new EdgeListGraph <TestVertex, Edge <TestVertex> >();

            RemoveEdgeIf_Throws_Test(graph);
        }
Exemplo n.º 14
0
        public void RemoveEdgeIf()
        {
            var graph = new EdgeListGraph <int, Edge <int> >();

            RemoveEdgeIf_EdgesOnly_Test(graph);
        }