示例#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 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());
        }
示例#3
0
        public void Edges_NormalTree_ListOfKeyValues()
        {
            mtg tree = new mtg();

            // Add 4 children. Parents/children are : (0 => 1), (1 => 2,3) , (3 => 4).
            int firstChild  = tree.AddChild(0);
            int secondChild = tree.AddChild(firstChild);
            int thirdChild  = tree.AddChild(firstChild);
            int fourthChild = tree.AddChild(thirdChild);

            // Assign a scale to each vertex.
            tree.scale[firstChild]  = 1;
            tree.scale[secondChild] = 1;
            tree.scale[thirdChild]  = 2;
            tree.scale[fourthChild] = 2;

            // Without specifying the scale
            List <KeyValuePair <int, int> > expectedResult = new List <KeyValuePair <int, int> >();

            expectedResult.Add(new KeyValuePair <int, int>(0, 1));
            expectedResult.Add(new KeyValuePair <int, int>(1, 2));
            expectedResult.Add(new KeyValuePair <int, int>(1, 3));
            expectedResult.Add(new KeyValuePair <int, int>(3, 4));

            CollectionAssert.AreEqual(expectedResult, tree.Edges());

            // Scale 0
            List <KeyValuePair <int, int> > expectedResult2 = new List <KeyValuePair <int, int> >();

            expectedResult2.Add(new KeyValuePair <int, int>(0, 1));
            CollectionAssert.AreEqual(expectedResult2, tree.Edges(0));

            // Scale 1
            List <KeyValuePair <int, int> > expectedResult3 = new List <KeyValuePair <int, int> >();

            expectedResult3.Add(new KeyValuePair <int, int>(1, 2));
            expectedResult3.Add(new KeyValuePair <int, int>(1, 3));
            CollectionAssert.AreEqual(expectedResult3, tree.Edges(1));

            // Scale 2
            List <KeyValuePair <int, int> > expectedResult4 = new List <KeyValuePair <int, int> >();

            expectedResult4.Add(new KeyValuePair <int, int>(3, 4));
            CollectionAssert.AreEqual(expectedResult4, tree.Edges(2));
        }
示例#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 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());
        }
示例#6
0
        public void Complex_NormalMtg_ComplexReturned()
        {
            mtg tree = new mtg();

            // Add 4 children. Parents/children are : (0 => 1), (1 => 2,3) , (3 => 4).
            int firstChild  = tree.AddChild(0);
            int secondChild = tree.AddChild(firstChild);
            int thirdChild  = tree.AddChild(firstChild);
            int fourthChild = tree.AddChild(thirdChild);
            int fifthChild  = tree.AddChild(0);

            // Assign a complex to the firstChild
            tree.complex.Add(firstChild, 0);

            Assert.AreEqual(tree.Complex(firstChild), 0);
            Assert.AreEqual(tree.Complex(secondChild), 0);
            Assert.AreEqual(tree.Complex(thirdChild), 0);
            Assert.AreEqual(tree.Complex(fourthChild), 0);

            Assert.IsNull(tree.Complex(fifthChild));
        }