public void RandomTree_DoChildrenAndParentCorrespond_CoherenceBetweenParentAndChildren() { mtg t = new mtg(); int lastVertex = algorithm.RandomTree(t, t.root, 5000, 100); foreach (int childId in t.parent.Keys) { if (childId != 0) { int?parentId = t.Parent(childId); Assert.IsNotNull(parentId); CollectionAssert.Contains(t.Children((int)parentId), childId); } } foreach (int parentId in t.children.Keys) { foreach (int childId in t.Children(parentId)) { Assert.AreEqual(t.Parent(childId), parentId); } } }
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()); }
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); }