예제 #1
0
        public void Components()
        {
            mtg tree = new mtg();
            int root = tree.root;

            // Scale 1

            int root1   = tree.AddComponent(root);
            int vertex1 = tree.AddChild(root1);
            int vertex2 = tree.AddChild(root1);
            int vertex3 = tree.AddChild(root1);
            int vertex4 = tree.AddChild(vertex1);
            int vertex5 = tree.AddChild(vertex1);

            // Verifications

            Assert.AreEqual(6, tree.NbComponents(root));

            List <int> expectedListOfComponents = new List <int>()
            {
                root1, vertex1, vertex4, vertex5, vertex2, vertex3
            };

            CollectionAssert.AreEqual(expectedListOfComponents, tree.Components(root));

            Assert.AreEqual(tree.NbComponents(root1), 0);
            Assert.AreEqual(tree.NbComponents(vertex1), 0);
            Assert.AreEqual(tree.NbComponents(vertex2), 0);
        }
예제 #2
0
        public void Clear()
        {
            mtg tree = new mtg();

            Assert.AreEqual(1, tree.NbVertices());

            int vertex1 = tree.AddComponent(tree.root);

            Assert.AreEqual(2, tree.NbVertices());

            tree.Clear();
            Assert.AreEqual(1, tree.NbVertices());

            int vertex2 = tree.AddComponent(tree.root);

            Assert.AreEqual(vertex1, vertex2);
        }
예제 #3
0
        public void MtgTest()
        {
            mtg tree = new mtg();

            int root = tree.root;

            Assert.AreEqual(0, root);

            // Scale 1

            int root1 = tree.AddComponent(root, new Dictionary <string, dynamic>()
            {
            });
            int vertex1 = tree.AddChild(root1);
            int vertex2 = tree.AddChild(root1);
            int vertex3 = tree.AddChild(root1);

            int vertex4 = tree.AddChild(vertex1);
            int vertex5 = tree.AddChild(vertex1);

            // Verify complex

            Assert.AreEqual(root, tree.Complex(root1));
            Assert.AreEqual(root, tree.Complex(vertex1));
            Assert.AreEqual(root, tree.Complex(vertex2));
            Assert.AreEqual(root, tree.Complex(vertex3));
            Assert.AreEqual(root, tree.Complex(vertex4));
            Assert.AreEqual(root, tree.Complex(vertex5));

            // Verify parents

            Assert.AreEqual(vertex1, tree.Parent(vertex5));
            Assert.AreEqual(vertex1, tree.Parent(vertex4));
            Assert.AreEqual(root1, tree.Parent(vertex3));
            Assert.AreEqual(root1, tree.Parent(vertex2));
            Assert.AreEqual(root1, tree.Parent(vertex1));

            // Verify children

            CollectionAssert.AreEqual(new List <int>()
            {
                vertex1, vertex2, vertex3
            }, tree.Children(root1));
            CollectionAssert.AreEqual(new List <int>()
            {
                vertex4, vertex5
            }, tree.Children(vertex1));
            Assert.IsFalse(tree.children.ContainsKey(vertex2));
            Assert.IsFalse(tree.children.ContainsKey(vertex3));
            Assert.IsFalse(tree.children.ContainsKey(vertex4));
            Assert.IsFalse(tree.children.ContainsKey(vertex5));

            // Verify length of the mtg

            Assert.AreEqual(7, tree.NbVertices());
        }
예제 #4
0
        public void AddChildAndComplex()
        {
            mtg tree = new mtg();
            int root = tree.root;

            int root1 = tree.AddComponent(root);
            int root2 = tree.AddComponent(root1);

            int vertex12 = tree.AddChild(root2);
            int vertex22 = tree.AddChild(vertex12);

            List <int> vertexAndComplex32 = tree.AddChildAndComplex(vertex22);

            int vertex32        = vertexAndComplex32[0];
            int vertex32complex = vertexAndComplex32[1];

            Assert.AreEqual(7, tree.NbVertices());
            CollectionAssert.Contains(tree.Children(vertex22), vertex32);
            CollectionAssert.Contains(tree.Children(root1), vertex32complex);
        }
예제 #5
0
        public void RandomTree()
        {
            Algorithm a = new Algorithm();

            mtg tree = new mtg();
            int root = tree.root;

            int root1 = tree.AddComponent(root);

            root1 = tree.AddComponent(root1);
            int vid = a.RandomTree(tree, root1, 18);

            List <int> childAndComplex = tree.AddChildAndComplex(vid);

            vid = a.RandomTree(tree, childAndComplex[0], 18);

            List <int> childAndComplex2 = tree.AddChildAndComplex(vid);

            vid = a.RandomTree(tree, childAndComplex2[0], 18);

            Assert.AreEqual(61, tree.NbVertices());
        }
예제 #6
0
        public void RemoveVertex()
        {
            mtg tree = new mtg();
            int root = tree.root;

            // Scale 1

            int root1   = tree.AddComponent(root);
            int vertex1 = tree.AddChild(root1);
            int vertex2 = tree.AddChild(root1);
            int vertex3 = tree.AddChild(root1);
            int vertex4 = tree.AddChild(vertex1);
            int vertex5 = tree.AddChild(vertex1);

            int numberVertices = tree.NbVertices();

            tree.RemoveVertex(vertex5);
            tree.RemoveVertex(vertex1, true);

            Assert.AreEqual(numberVertices - 2, tree.NbVertices());
        }
예제 #7
0
        public void Properties()
        {
            Algorithm a = new Algorithm();

            mtg tree = new mtg();
            int root = tree.root;

            int root1 = tree.AddComponent(root);
            int vid   = a.RandomTree(tree, root1, 18);

            List <int> childAndComplex = tree.AddChildAndComplex(vid);

            vid = a.RandomTree(tree, childAndComplex[0], 18);

            List <int> childAndComplex2 = tree.AddChildAndComplex(vid);

            vid = a.RandomTree(tree, childAndComplex2[0], 18);

            Assert.IsTrue(tree.PropertyNames().Contains("Edge_Type"));
            Assert.AreEqual(18 * 3, tree.Property("Edge_Type").Count);
        }