Example #1
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));
        }
Example #2
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));
        }
        protected static void ContainsEdge_EquatableEdge_EdgesOnly_Test(
            [NotNull] EdgeListGraph <int, EquatableEdge <int> > graph)
        {
            var edge1      = new EquatableEdge <int>(1, 2);
            var edge2      = new EquatableEdge <int>(1, 3);
            var edge3      = new EquatableEdge <int>(2, 1);
            var edge4      = new EquatableEdge <int>(2, 2);
            var otherEdge1 = new EquatableEdge <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));

            graph.AddVerticesAndEdge(edge1);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsFalse(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            graph.AddVerticesAndEdge(edge2);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsFalse(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            graph.AddVerticesAndEdge(edge3);
            Assert.IsTrue(graph.ContainsEdge(edge1));
            Assert.IsTrue(graph.ContainsEdge(edge2));
            Assert.IsTrue(graph.ContainsEdge(edge3));
            Assert.IsFalse(graph.ContainsEdge(edge4));
            Assert.IsTrue(graph.ContainsEdge(otherEdge1));

            graph.AddVerticesAndEdge(edge4);
            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));

            graph.AddVerticesAndEdge(otherEdge1);
            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 EquatableEdge <int>(0, 10)));
            // Source not in graph
            Assert.IsFalse(graph.ContainsEdge(new EquatableEdge <int>(0, 1)));
            // Target not in graph
            Assert.IsFalse(graph.ContainsEdge(new EquatableEdge <int>(1, 0)));
        }