protected static void ContainsVertex_OnlyEdges_Test(
            EdgeListGraph <TestVertex, Edge <TestVertex> > graph)
        {
            var vertex1        = new TestVertex("1");
            var toVertex1      = new TestVertex("target 1");
            var vertex2        = new TestVertex("2");
            var toVertex2      = new TestVertex("target 2");
            var otherVertex1   = new TestVertex("1");
            var toOtherVertex1 = new TestVertex("target 1");

            Assert.IsFalse(graph.ContainsVertex(vertex1));
            Assert.IsFalse(graph.ContainsVertex(vertex2));
            Assert.IsFalse(graph.ContainsVertex(otherVertex1));

            graph.AddEdge(new Edge <TestVertex>(vertex1, toVertex1));
            Assert.IsTrue(graph.ContainsVertex(vertex1));
            Assert.IsFalse(graph.ContainsVertex(otherVertex1));

            graph.AddEdge(new Edge <TestVertex>(vertex2, toVertex2));
            Assert.IsTrue(graph.ContainsVertex(vertex2));

            graph.AddEdge(new Edge <TestVertex>(otherVertex1, toOtherVertex1));
            Assert.IsTrue(graph.ContainsVertex(vertex1));
            Assert.IsTrue(graph.ContainsVertex(otherVertex1));
        }
Пример #2
0
        public void EdgeListGraphTestAddStuff()
        {
            var g = new EdgeListGraph <int, IEdge <int> >();

            g.AddEdge(new Edge <int>(0, 1));
            Assert.AreEqual(2, g.VertexCount);
            Assert.AreEqual(1, g.EdgeCount);
            g.AddEdge(new Edge <int>(0, 1));
            Assert.AreEqual(2, g.VertexCount);
            Assert.AreEqual(2, g.EdgeCount);
            g.AddEdge(new EquatableEdge <int>(0, 2));
            Assert.AreEqual(3, g.VertexCount);
            Assert.AreEqual(3, g.EdgeCount);
            g.AddVerticesAndEdge(new Edge <int>(3, 4));
            Assert.AreEqual(5, g.VertexCount);
            Assert.AreEqual(4, g.EdgeCount);
            g.AddEdgeRange(new List <IEdge <int> > {
                new Edge <int>(4, 5)
            });
            Assert.AreEqual(6, g.VertexCount);
            Assert.AreEqual(5, g.EdgeCount);
            g.AddVerticesAndEdgeRange(new List <IEdge <int> > {
                new Edge <int>(4, 5)
            });
            Assert.AreEqual(6, g.VertexCount);
            Assert.AreEqual(6, g.EdgeCount);
        }
 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>> 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;
 }
 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;
 }
Пример #6
0
        public void EdgeListGraphTestAddStuffNoParalelEquateable()
        {
            var g = new EdgeListGraph <int, EquatableEdge <int> >(true, false);

            g.AddEdge(new EquatableEdge <int>(0, 1));
            Assert.AreEqual(2, g.VertexCount);
            Assert.AreEqual(1, g.EdgeCount);
            g.AddEdge(new EquatableEdge <int>(0, 1));
            Assert.AreEqual(2, g.VertexCount);
            Assert.AreEqual(1, g.EdgeCount);
        }
Пример #7
0
        public void RemoveEdgeTest()
        {
            var g = new EdgeListGraph <int, EquatableEdge <int> >(true, false);
            EquatableEdge <int> e = new EquatableEdge <int>(0, 1);

            g.AddEdge(e);
            Assert.IsTrue(g.RemoveEdge(e));
            Assert.IsFalse(g.RemoveEdge(e));
        }
Пример #8
0
        public void EdgeListGraphTestContainsEquateable()
        {
            var g = new EdgeListGraph <int, EquatableEdge <int> >(true, false);

            g.AddEdge(new EquatableEdge <int>(0, 1));
            Assert.IsTrue(g.ContainsEdge(new EquatableEdge <int>(0, 1)));
            Assert.IsFalse(g.ContainsEdge(new EquatableEdge <int>(2, 1)));
            Assert.IsTrue(g.ContainsVertex(0));
            Assert.IsTrue(g.ContainsVertex(1));
            Assert.IsFalse(g.ContainsVertex(2));
        }
Пример #9
0
        public void EdgeListGraphTestContains()
        {
            var g = new EdgeListGraph <int, IEdge <int> >(true, false);
            var e = new Edge <int>(0, 1);

            g.AddEdge(e);
            Assert.IsTrue(g.ContainsEdge(e));
            Assert.IsTrue(g.ContainsEdge(new Edge <int>(0, 1)));
            Assert.IsFalse(g.ContainsEdge(new Edge <int>(2, 1)));
            Assert.IsTrue(g.ContainsVertex(0));
            Assert.IsTrue(g.ContainsVertex(1));
            Assert.IsFalse(g.ContainsVertex(2));
        }
Пример #10
0
        /// <summary>
        /// Cria um grafo não direccionado complexo para teste.
        /// </summary>
        /// <returns>O grafo.</returns>
        private EdgeListGraph <int> CreateTestGraph_Undirected()
        {
            var result = new EdgeListGraph <int>();

            for (var i = 1; i <= 10; ++i)
            {
                result.AddVertex(i);
            }

            result.AddEdge(1, 2);
            result.AddEdge(1, 4);
            result.AddEdge(4, 7);
            result.AddEdge(7, 10);
            result.AddEdge(7, 9);
            result.AddEdge(2, 5);
            result.AddEdge(3, 5);
            result.AddEdge(3, 6);
            result.AddEdge(5, 8);
            result.AddEdge(6, 7);
            result.AddEdge(6, 8);
            result.AddEdge(6, 9);

            return(result);
        }
 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;
 }