Inheritance: IVertex
コード例 #1
0
ファイル: GraphTests.cs プロジェクト: sethjuarez/numl
        public void ChildVertexTest()
        {
            Vertex.Reset();
            Graph g = new Graph();
            var vertex1 = new Vertex();
            g.AddVertex(vertex1); // 1
            g.AddVertex(new Vertex()); // 2
            g.AddVertex(new Vertex()); // 3
            g.AddVertex(new Vertex()); // 4
            g.AddVertex(new Vertex()); // 5

            g.AddEdge(new Edge { ParentId = 1, ChildId = 5 });
            g.AddEdge(new Edge { ParentId = 1, ChildId = 2 });
            g.AddEdge(new Edge { ParentId = 2, ChildId = 3 });

            var children = g.GetChildren(vertex1).ToArray();
            Assert.Equal(2, children.Length);

            Assert.True(children.Select(e => e.Id).ToArray().Contains(5));
            Assert.True(children.Select(e => e.Id).ToArray().Contains(2));

        }
コード例 #2
0
ファイル: GraphTests.cs プロジェクト: sethjuarez/numl
        public void OutEdgesVertexTest()
        {
            Vertex.Reset();
            Graph g = new Graph();
            var vertex1 = new Vertex();
            g.AddVertex(vertex1); // 1
            g.AddVertex(new Vertex()); // 2
            g.AddVertex(new Vertex()); // 3
            g.AddVertex(new Vertex()); // 4
            g.AddVertex(new Vertex()); // 5

            g.AddEdge(new Edge { ParentId = 1, ChildId = 5 });
            g.AddEdge(new Edge { ParentId = 1, ChildId = 2 });
            g.AddEdge(new Edge { ParentId = 2, ChildId = 3 });

            var edges = g.GetOutEdges(vertex1).ToArray();
            Assert.Equal(2, edges.Length);

            Assert.True(edges.Select(e => e.ParentId).Distinct().Count() == 1);
            Assert.Equal(1, edges.Select(e => e.ParentId).Distinct().First());
            Assert.True(edges.Select(e => e.ChildId).Contains(5));
            Assert.True(edges.Select(e => e.ChildId).Contains(2));

        }
コード例 #3
0
ファイル: GraphTests.cs プロジェクト: sethjuarez/numl
        public void RemoveVertexTest()
        {
            Vertex.Reset();
            Graph g = new Graph();
            var vertex1 = new Vertex();
            g.AddVertex(vertex1); // 1
            g.AddVertex(new Vertex()); // 2
            g.AddVertex(new Vertex()); // 3
            g.AddVertex(new Vertex()); // 4
            g.AddVertex(new Vertex()); // 5

            g.AddEdge(new Edge { ParentId = 1, ChildId = 5 });
            g.AddEdge(new Edge { ParentId = 1, ChildId = 2 });
            g.AddEdge(new Edge { ParentId = 2, ChildId = 3 });
            g.AddEdge(new Edge { ParentId = 3, ChildId = 1 });

            g.RemoveVertex(vertex1);

            Assert.Equal(0, g.GetVertices().Where(v => v.Id == 1).Count());
            Assert.Equal(0, g.GetEdges().Where(e => e.ParentId == 1 || e.ChildId == 1).Count());
        }
コード例 #4
0
ファイル: GraphTests.cs プロジェクト: sethjuarez/numl
        public void TreeNotEqualTest()
        {
            Vertex.Reset();
            Tree g1 = new Tree();
            var r1 = new Vertex();
            g1.Root = r1;
            g1.AddVertex(r1); // 1
            g1.AddVertex(new Vertex()); // 2
            g1.AddVertex(new Vertex()); // 3
            g1.AddVertex(new Vertex()); // 4
            g1.AddVertex(new Vertex()); // 5
            g1.AddVertex(new Vertex()); // 6
            g1.AddVertex(new Vertex()); // 7

            g1.AddEdge(new Edge { ParentId = 1, ChildId = 2 });
            g1.AddEdge(new Edge { ParentId = 1, ChildId = 3 });
            g1.AddEdge(new Edge { ParentId = 2, ChildId = 4 });
            g1.AddEdge(new Edge { ParentId = 2, ChildId = 5 });
            g1.AddEdge(new Edge { ParentId = 3, ChildId = 6 });
            g1.AddEdge(new Edge { ParentId = 3, ChildId = 7 });

            Vertex.Reset();
            Tree g2 = new Tree();
            var r2 = new Vertex();
            g2.Root = r2;
            g2.AddVertex(r2); // 1
            g2.AddVertex(new Vertex()); // 2
            g2.AddVertex(new Vertex()); // 3
            g2.AddVertex(new Vertex()); // 4
            g2.AddVertex(new Vertex()); // 5
            g2.AddVertex(new Vertex()); // 6
            g2.AddVertex(new Vertex()); // 7

            g2.AddEdge(new Edge { ParentId = 1, ChildId = 2 });
            g2.AddEdge(new Edge { ParentId = 1, ChildId = 3 });
            g2.AddEdge(new Edge { ParentId = 2, ChildId = 4 });
            g2.AddEdge(new Edge { ParentId = 2, ChildId = 5 });
            g2.AddEdge(new Edge { ParentId = 1, ChildId = 6 });
            g2.AddEdge(new Edge { ParentId = 3, ChildId = 7 });

            Assert.False(g1.Equals(g2));
        }
コード例 #5
0
ファイル: GraphTests.cs プロジェクト: sethjuarez/numl
        public void ParentVertexTest()
        {
            Vertex.Reset();
            Graph g = new Graph();
            var vertex1 = new Vertex();
            g.AddVertex(vertex1); // 1
            g.AddVertex(new Vertex()); // 2
            g.AddVertex(new Vertex()); // 3
            g.AddVertex(new Vertex()); // 4
            g.AddVertex(new Vertex()); // 5

            g.AddEdge(new Edge { ParentId = 5, ChildId = 1 });
            g.AddEdge(new Edge { ParentId = 2, ChildId = 1 });
            g.AddEdge(new Edge { ParentId = 2, ChildId = 3 });

            var parents = g.GetParents(vertex1).ToArray();
            Assert.Equal(2, parents.Length);

            Assert.True(parents.Select(e => e.Id).ToArray().Contains(5));
            Assert.True(parents.Select(e => e.Id).ToArray().Contains(2));
        }