Exemplo n.º 1
0
        public void InsertSibling_AddSiblingToATree_SiblingAndPropertiesAdded()
        {
            // PropertyTree: {0 => 1 , 2} and {1 => 3 , 4}

            PropertyTree tree = new PropertyTree();

            int firstChild  = tree.AddChild(tree.root);
            int secondChild = tree.AddChild(tree.root);

            int thirdChild  = tree.AddChild(firstChild);
            int fourthChild = tree.AddChild(firstChild);

            // Add siblings so that: {0 => 1,5,2} & {1 => 6,3,4}

            int firstSibling = tree.InsertSibling(secondChild, namesValues: new Dictionary <string, dynamic>()
            {
                { "Edge_Type", "<" }
            });
            int secondSibling = tree.InsertSibling(thirdChild, namesValues: new Dictionary <string, dynamic>()
            {
                { "Edge_Type", "+" }
            });

            // Verification of the parents

            Assert.AreEqual(tree.root, tree.Parent(firstSibling));
            Assert.AreEqual(tree.root, tree.Parent(secondChild));
            Assert.AreEqual(firstChild, tree.Parent(secondSibling));
            Assert.AreEqual(firstChild, tree.Parent(thirdChild));

            // Verification of the children (and the correct order)

            CollectionAssert.AreEqual(new List <int>()
            {
                firstChild, firstSibling, secondChild
            }, tree.Children(tree.root));
            CollectionAssert.AreEqual(new List <int>()
            {
                secondSibling, thirdChild, fourthChild
            }, tree.Children(firstChild));

            // Verification of the insertion of the properties

            Assert.IsTrue(tree.properties.ContainsKey("Edge_Type"));

            Dictionary <string, dynamic> props = new Dictionary <string, dynamic>();

            props.Add("Edge_Type", "<");

            CollectionAssert.AreEqual(tree.GetVertexProperties(firstSibling), props);

            props["Edge_Type"] = "+";
            CollectionAssert.AreEqual(tree.GetVertexProperties(secondSibling), props);
        }
Exemplo n.º 2
0
        public void AddChild_NormalCase_ChildAndPropertiesAdded()
        {
            PropertyTree tree = new PropertyTree();

            // The properties to add
            Dictionary <string, dynamic> propertyDict = new Dictionary <string, dynamic>();

            propertyDict.Add("label", "leaf");
            propertyDict.Add("length", 12.5);
            propertyDict.Add("order", 1);

            int childId = tree.AddChild(tree.root, propertyDict);

            // Make sure the child was added
            Assert.IsTrue(tree.Children(tree.root).Contains(childId));
            Assert.AreEqual(tree.Children(tree.root).Count(), 1);
            Assert.AreEqual(tree.Parent(childId), tree.root);

            // Make sure the properties were correctly added
            Dictionary <string, Dictionary <int, dynamic> > expectedResult = new Dictionary <string, Dictionary <int, dynamic> >();
            Dictionary <int, dynamic> firstRow = new Dictionary <int, dynamic>()
            {
                { childId, "leaf" }
            };
            Dictionary <int, dynamic> secondRow = new Dictionary <int, dynamic>()
            {
                { childId, 12.5 }
            };
            Dictionary <int, dynamic> thirdRow = new Dictionary <int, dynamic>()
            {
                { childId, 1 }
            };

            expectedResult.Add("label", firstRow);
            expectedResult.Add("length", secondRow);
            expectedResult.Add("order", thirdRow);

            CollectionAssert.AreEqual(expectedResult.Keys, tree.properties.Keys);
            CollectionAssert.AreEqual(expectedResult["label"], tree.properties["label"]);
            CollectionAssert.AreEqual(expectedResult["length"], tree.properties["length"]);
            CollectionAssert.AreEqual(expectedResult["order"], tree.properties["order"]);
        }
Exemplo n.º 3
0
        public void AddChild_NoProperties_ChildAddedAndNoPropertiesForTheChild()
        {
            PropertyTree tree = new PropertyTree();

            Dictionary <string, dynamic> propertyDict = new Dictionary <string, dynamic>()
            {
            };

            int childId = tree.AddChild(tree.root, propertyDict);

            // Make sure the child was added
            Assert.IsTrue(tree.Children(tree.root).Contains(childId));
            Assert.AreEqual(tree.Children(tree.root).Count(), 1);
            Assert.AreEqual(tree.Parent(childId), tree.root);

            // Make sure the dictionary is empty
            Dictionary <string, Dictionary <int, dynamic> > expectedProperties = new Dictionary <string, Dictionary <int, dynamic> >()
            {
            };

            CollectionAssert.AreEqual(tree.properties, expectedProperties);
        }