public void SimpleTree() { mtg tree = new mtg(); tree = algorithm.SimpleTree(tree, tree.root); IEnumerable <int> s1 = t.IterativePreOrder(tree, tree.root); IEnumerable <int> s2 = t.IterativePostOrder(tree, tree.root); Func <IEnumerable <int>, int> Counter = new Func <IEnumerable <int>, int>(source => { int res = 0; foreach (var item in source) { res++; } return(res); }); Assert.AreEqual(21, tree.NbVertices()); Assert.AreEqual(Counter(s1), Counter(s2)); Assert.AreEqual(21, Counter(s1)); }
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); }
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 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()); }
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); }
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()); }
public void NbVertices_NormalMtg_CorrectNumberForEachScale() { mtg tree = new mtg(); tree.scale.Add(1, 1); tree.scale.Add(2, 1); tree.scale.Add(3, 3); tree.scale.Add(4, 5); // Counts all vertices since scale isn't specified. Assert.AreEqual(tree.NbVertices(), 5); // Gives the right count for vertices by scale. Assert.AreEqual(tree.NbVertices(0), 1); Assert.AreEqual(tree.NbVertices(1), 2); Assert.AreEqual(tree.NbVertices(3), 1); Assert.AreEqual(tree.NbVertices(5), 1); // Gives answer zero for a scale which doesn't exist. Assert.AreEqual(tree.NbVertices(2), 0); }