Example #1
0
        public void TreeEntityExtensions_GetPrefixTree()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);

            TreeNode node4 = new TreeNode();

            node2.AppendChild(node4);
            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node3.AppendChild(node5);
            node3.AppendChild(node6);

            List <TreeNode> list = TreeEntityExtensions.GetPrefixTree(tree).ToList();

            Assert.Equal(new TreeNode[]
            {
                node1,
                node2,
                node4,
                node3,
                node5,
                node6
            }, list);
        }
Example #2
0
        public void TreeHelper_SetTreeForChildNodes()
        {
            TreeNode root  = new TreeNode();
            TreeNode node1 = new TreeNode();
            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();
            TreeNode node4 = new TreeNode();

            root.ChildNodes.Add(node1);
            root.ChildNodes.Add(node2);
            node1.ChildNodes.Add(node3);
            node2.ChildNodes.Add(node4);

            TestTree tree = new TestTree();

            root.Tree = tree;

            TreeHelper.SetTreeForChildNodes(root);

            Assert.Same(tree, root.Tree);
            Assert.Same(tree, node1.Tree);
            Assert.Same(tree, node2.Tree);
            Assert.Same(tree, node3.Tree);
            Assert.Same(tree, node4.Tree);
        }
Example #3
0
        public void SameCategoryShouldNotBeSelectedMoreThanOnce()
        {
            // arrange
            TestTree target = new TestTree();

            // we need to populate the available categories
            // this can be done via TestLoader but this way the test is isolated
            FieldInfo fieldInfo = typeof(TestTree).GetField("availableCategories", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fieldInfo, "The field 'availableCategories' should be found.");
            object fieldValue = fieldInfo.GetValue(target);

            Assert.IsNotNull(fieldValue, "The value of 'availableCategories' should not be null.");
            IList availableCategories = fieldValue as IList;

            Assert.IsNotNull(availableCategories, "'availableCategories' field should be of type IList.");

            string[] expectedSelectedCategories = new string[] { "Foo", "MockCategory" };
            foreach (string availableCategory in expectedSelectedCategories)
            {
                availableCategories.Add(availableCategory);
            }

            // act
            //target.SelectCategories(expectedSelectedCategories, true);
            //target.SelectCategories(expectedSelectedCategories, true);
            string[] actualSelectedCategories = target.SelectedCategories;

            // assert
            CollectionAssert.AreEquivalent(expectedSelectedCategories, actualSelectedCategories);
        }
        public unsafe void Benchmark_Walk()
        {
            int      depthLimit         = 25;
            int      expectedNodesCount = (1 << (depthLimit + 1)) - 1;
            TestTree tree = new TestTree(expectedNodesCount);
            int      idx  = 0;

            CreateTestTree(tree, idx, ref idx, 0, depthLimit, 2);

            WalkUFTreePP <TestTree, Context> walker =
                new WalkUFTreePP <TestTree, Context>();

            int nodeCount = 0;

            walker.OnNodeBegin = (t, s, d) => { nodeCount++; };

            DateTime startTime = DateTime.Now;

            walker.Walk(tree);

            double time = (DateTime.Now - startTime).TotalSeconds;

            Assert.AreEqual(expectedNodesCount, nodeCount);

            Console.WriteLine("Node count {0:###,###,###}, {1} s, {2:###,###,###} n/s",
                              nodeCount, time, nodeCount / time);
        }
        private void VerifyWalk(TestTree tree, UFToUniAdapter adapter)
        {
            List <int> expectedPre  = new List <int>();
            List <int> expectedPost = new List <int>();

            WalkUFTreePP <TestTree, WalkUFTreePPContext> wft =
                new WalkUFTreePP <TestTree, WalkUFTreePPContext>();

            wft.OnNodeBegin = (t, s, d) => expectedPre.Add(tree.Nodes[s[d].NodeIdx].Value);
            wft.OnNodeEnd   = (t, s, d) => expectedPost.Add(tree.Nodes[s[d].NodeIdx].Value);

            wft.Walk(tree);

            List <int> actualPre  = new List <int>();
            List <int> actualPost = new List <int>();

            WalkTreePP <UFToUniAdapter, int, int, AdapterContext> wt = new WalkTreePP <UFToUniAdapter, int, int, AdapterContext>();

            wt.OnNodeBegin = (t, n, s, d) =>
            {
                actualPre.Add(tree.Nodes[n].Value);
                return(true);
            };
            wt.OnNodeEnd = (t, n, s, d) => actualPost.Add(tree.Nodes[n].Value);

            wt.Walk(adapter, 0);

            Assert.AreEqual(expectedPre, actualPre);
            Assert.AreEqual(expectedPost, actualPost);

            int bi, cnt;

            adapter.GetChildrenBeginIdxAndCount(0, out bi, out cnt);
            Assert.AreEqual(4, cnt);
        }
 public static void PrintLevels(TestTree t)
 {
     for (int i = 0; i <= t.Root.Level; i++)
     {
         PrintBoundables(t.BoundablesAtLevel(i), "Level " + i);
     }
 }
		public void SameCategoryShouldNotBeSelectedMoreThanOnce()
		{
			// arrange
			TestTree target = new TestTree();

			// we need to populate the available categories
			// this can be done via TestLoader but this way the test is isolated
			FieldInfo fieldInfo = typeof (TestTree).GetField("availableCategories", BindingFlags.NonPublic | BindingFlags.Instance);
			Assert.IsNotNull(fieldInfo, "The field 'availableCategories' should be found.");
			object fieldValue = fieldInfo.GetValue(target);
			Assert.IsNotNull(fieldValue, "The value of 'availableCategories' should not be null.");
			IList availableCategories = fieldValue as IList;
			Assert.IsNotNull(availableCategories, "'availableCategories' field should be of type IList.");

			string[] expectedSelectedCategories = new string[] { "Foo", "MockCategory" };
			foreach (string availableCategory in expectedSelectedCategories)
			{
				availableCategories.Add(availableCategory);
			}

			// act
			target.SelectCategories(expectedSelectedCategories, true);
			target.SelectCategories(expectedSelectedCategories, true);
			string[] actualSelectedCategories = target.SelectedCategories;

			// assert
			CollectionAssert.AreEquivalent(expectedSelectedCategories, actualSelectedCategories);
		}
Example #8
0
        public void Test_StructureDiffers_SameNodesCount()
        {
            int      expectedNodesCount = 1 + 4 + 4 * 4;
            TestTree tree1 = new TestTree(expectedNodesCount);
            int      idx   = 0;

            CreateTestTree(tree1, idx, ref idx, 0, 2, 4);
            TestTree tree2 = new TestTree(expectedNodesCount);

            idx = 0;
            CreateTestTree(tree2, idx, ref idx, 0, 2, 4);

            // Now move node 19 (last node in PP to be a child) of the root,
            // and set node 20 as child of node 19.
            Assert.AreEqual(2, tree2.GetDepth(19));
            Assert.AreEqual(2, tree2.GetDepth(20));
            tree2.SetDepth(19, (byte)1);
            tree2.SetDepth(20, (byte)2);

            CompareUFTrees <TestTree, TestTree> comp = new CompareUFTrees <TestTree, TestTree>();
            bool result = comp.Compare(tree1, tree2, (t1, t2, n) => t1.Nodes[n].Value == t2.Nodes[n].Value);

            Assert.IsFalse(result);
            Assert.AreEqual(CompareUFTrees.ResultKind.StructureDiffers, comp.Result);
            Assert.AreEqual(19, comp.DiffersAt);
        }
Example #9
0
        public void TreeEntityExtensions_GetSize()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);

            TreeNode node4 = new TreeNode();

            node2.AppendChild(node4);
            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node3.AppendChild(node5);
            node3.AppendChild(node6);

            int size = TreeEntityExtensions.GetSize(tree);

            Assert.Equal(6, size);
        }
Example #10
0
        public unsafe void Test_ReadWrite()
        {
            int      nodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4;
            TestTree tree       = new TestTree(nodesCount);
            int      idx        = 0;

            CreateTestTree(tree, ref idx, 0, 3, 4);
            tree.Version.Major = 4;
            tree.Version.Minor = 2;
            tree.UserData      = 1234567;

            MemoryStream ms = new MemoryStream();
            BinaryWriter w  = new BinaryWriter(ms);

            tree.Write(w);
            byte[] buffer = ms.ToArray();
            ms = new MemoryStream(buffer);
            BinaryReader r     = new BinaryReader(ms);
            TestTree     tree1 = TestTree.Read <TestTree>(r);

            Assert.AreEqual(tree.Version, tree1.Version);
            Assert.AreEqual(tree.UserData, tree1.UserData);
            Assert.AreEqual(tree.NodesCount, tree1.NodesCount);
            for (int i = 0; i < tree.NodesCount; ++i)
            {
                Assert.AreEqual(tree.GetDepth(i), tree1.GetDepth(i));
                Assert.AreEqual(tree.Nodes[i].Id, tree1.Nodes[i].Id);
            }
        }
Example #11
0
        public unsafe void Test_ReadWriteFDA()
        {
            int      nodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4;
            TestTree tree       = new TestTree(nodesCount);
            int      idx        = 0;

            CreateTestTree(tree, ref idx, 0, 3, 4);
            tree.Version.Major = 4;
            tree.Version.Minor = 2;
            tree.UserData      = 1234567;
            string fileName = Path.Combine(_outDir, "uftree.dat");

            tree.Write(fileName);
            TestTree tree1 = TestTree.ReadFDA <TestTree>(fileName);

            Assert.AreEqual(tree.Version, tree1.Version);
            // Do not check the user data, it is not supported by FDA
            Assert.AreEqual(tree.NodesCount, tree1.NodesCount);
            for (int i = 0; i < tree.NodesCount; ++i)
            {
                Assert.AreEqual(tree.GetDepth(i), tree1.GetDepth(i), i.ToString());
                TestNode n, n1;
                tree.GetNode(i, (byte *)&n);
                tree1.GetNode(i, (byte *)&n1);
                Assert.AreEqual(n.Id, n1.Id, i.ToString());
            }
        }
 private static void InitTree(TestTree t, IList <Envelope> sourceEnvelopes)
 {
     foreach (var sourceEnvelope in sourceEnvelopes)
     {
         t.Insert(sourceEnvelope, sourceEnvelope);
     }
     t.Build();
 }
        public STRtreeDemo()
        {
            var      envelopes = SourceData();
            TestTree t         = new TestTree(NODE_CAPACITY);

            InitTree(t, envelopes);
            PrintSourceData(envelopes);
            PrintLevels(t);
        }
Example #14
0
        public void RecursiveTest()
        {
            var testTree = new TestTree("Parent");

            var child1 = new TestTree("Child_1");

            child1.Children.AddRange(new[]
            {
                new TestTree("Child_1-a"),
                new TestTree("Child_1-b"),
            });
            var child2 = new TestTree("Child_2");

            child2.Children.AddRange(new[]
            {
                new TestTree("Child_2-a"),
                new TestTree("Child_2-b"),
                new TestTree("Child_2-c"),
            });
            var child3 = new TestTree("Child_3");

            child3.Children.AddRange(new[]
            {
                new TestTree("Child_3-a"),
                new TestTree("Child_3-b"),
            });

            var child3c = new TestTree("Child_3-c");

            child3c.Children.AddRange(new[]
            {
                new TestTree("Child_3-c-1"),
                new TestTree("Child_3-c-2"),
                new TestTree("Child_3-c-3"),
            });

            child3.Children.Add(child3c);
            child3.Children.Add(new TestTree("Child_3-d"));

            testTree.Children.Add(child1);
            testTree.Children.Add(child2);
            testTree.Children.Add(child3);

            var actual = testTree
                         .Recursive(each => each.Children)
                         .Select(tree => tree.Value);

            var expected = new[]
            {
                "Child_1", "Child_2", "Child_3",
                "Child_1-a", "Child_1-b", "Child_2-a", "Child_2-b", "Child_2-c", "Child_3-a", "Child_3-b", "Child_3-c", "Child_3-d",
                "Child_3-c-1", "Child_3-c-2", "Child_3-c-3",
            };

            Assert.IsTrue(actual.SequenceEqual(expected));
        }
 public void TestEmptyTree()
 {
     TestTree t = new TestTree(2);
     t.Build();
     Assert.AreEqual(0, t.Root().Level);
     Assert.AreEqual(1, t.BoundablesAtLevel(0).Count);
     Assert.AreEqual(0, t.BoundablesAtLevel(1).Count);
     Assert.AreEqual(0, t.BoundablesAtLevel(-1).Count);
     Assert.AreEqual(0, t.Query(0.5, 0.5).Count);
 }
Example #16
0
        public void Setup()
        {
            _rand = new Random(5765113); //Just choosing a seed so our test is always the same

            TestObjects = GenerateTree(20);
            Options     = new JsonWriterOptions()
            {
                SkipValidation = true
            };
        }
Example #17
0
        public void TestEmptyTree()
        {
            var t = new TestTree(2);

            t.Build();
            Assert.AreEqual(0, t.Root().Level);
            Assert.AreEqual(1, t.BoundablesAtLevel(0).Count);
            Assert.AreEqual(0, t.BoundablesAtLevel(1).Count);
            Assert.AreEqual(0, t.BoundablesAtLevel(-1).Count);
            Assert.AreEqual(0, t.Query(0.5, 0.5).Count);
        }
        public void Test_Walk_FromMemory()
        {
            int      expectedNodesCount = 1 + 4 + 4 * 4;// +4 * 4 * 4;
            TestTree tree = new TestTree(expectedNodesCount);
            int      idx  = 0;

            CreateTestTree(tree, ref idx, 0, 2, 4);
            UFToUniAdapter adapter = new UFToUniAdapter(tree);

            VerifyWalk(tree, adapter);
        }
        public void Test_Walk_FromFile()
        {
            int      expectedNodesCount = 1 + 4 + 4 * 4;// +4 * 4 * 4;
            TestTree tree = new TestTree(expectedNodesCount);
            int      idx  = 0;

            CreateTestTree(tree, ref idx, 0, 2, 4);
            UFToUniAdapter adapter = new UFToUniAdapter(tree, Path.Combine(_outDir, "index.dat"), false);

            VerifyWalk(tree, adapter);
        }
        public void TestChainGetWithIndexes()
        {
            var chain = new TestTree(0)
            {
                Nodes = new[] { new TestNode(1, new TestNode(2, null)) }
            };

            var id = chain.ChainGet(c => c.Nodes[0].Node.Node.Id);

            Assert.AreEqual(2, id);
        }
Example #21
0
        public void TreeEnumeratorForeachTest()
        {
            List<string> output = new List<string>();
            var tree = new TestTree();

            foreach (var node in tree)
            {
                output.Add(node.Value);
            }
            string target = string.Join(",", output);

            Assert.AreEqual(tree.Expectation, target);
        }
Example #22
0
 unsafe void CreateTestTree(TestTree tree, ref int nodeIdx, int curDepth, int depthLimit, int childCount)
 {
     if (curDepth > depthLimit)
     {
         return;
     }
     tree.SetDepth(nodeIdx, (byte)curDepth);
     tree.Nodes[nodeIdx].Id = nodeIdx++;
     for (int c = 0; c < childCount; ++c)
     {
         CreateTestTree(tree, ref nodeIdx, curDepth + 1, depthLimit, childCount);
     }
 }
Example #23
0
        private TestTree GenerateTree(int maxDepth)
        {
            var tree = new TestTree()
            {
                Value = _rand.Next().ToString()
            };

            if (maxDepth > 0)
            {
                maxDepth--;
                tree.Left  = GenerateTree(maxDepth - 1);
                tree.Right = GenerateTree(maxDepth - 1);
            }
            return(tree);
        }
Example #24
0
        public void TreeHelper_ReplaceNodeInTree()
        {
            TestTree tree1              = CreateTree1();
            TestTree tree2              = CreateTree2();
            TreeNode movingNode         = tree1.RootNode.ChildNodes[0]; // node2
            TreeNode locationNode       = tree2.RootNode.ChildNodes[2]; // node4
            TreeNode locationParentNode = locationNode.ParentNode;

            TreeHelper.ReplaceNodeInTree(movingNode, tree2, locationNode, locationParentNode);

            Assert.Equal(3, locationParentNode.ChildNodes.Count);
            Assert.DoesNotContain(locationNode, locationParentNode.ChildNodes);
            Assert.Same(movingNode, locationParentNode.ChildNodes[2]);
            Assert.Single(movingNode.ChildNodes);
        }
Example #25
0
 unsafe void CreateTestTree(TestTree tree, int nodeImmutableIdx, ref int nodeIdx, int curDepth, int depthLimit, int childCount)
 {
     if (curDepth > depthLimit)
     {
         return;
     }
     Assert.AreEqual(nodeImmutableIdx, nodeIdx);
     tree.SetDepth(nodeIdx, (byte)curDepth);
     tree.Nodes[nodeIdx].Value = nodeIdx;
     nodeIdx++;
     for (int c = 0; c < childCount; ++c)
     {
         CreateTestTree(tree, nodeIdx, ref nodeIdx, curDepth + 1, depthLimit, childCount);
     }
 }
Example #26
0
        /// <summary>
        /// 构建删除8后的期望树
        /// </summary>
        /// <returns></returns>
        static TestTree BuildExpectedTreeAfterDelete8()
        {
            TestTree tree = new TestTree();

            List<TreeBuildNode<int>> dlrList = new List<TreeBuildNode<int>>(); //前序序列
            List<TreeBuildNode<int>> ldrList = new List<TreeBuildNode<int>>(); //中序序列

            TreeBuildNode<int> node1 = new TreeBuildNode<int>() { Data = 1, Colour = TreeNodeColor.Black };
            TreeBuildNode<int> node6 = new TreeBuildNode<int>() { Data = 6, Colour = TreeNodeColor.Red };
            TreeBuildNode<int> node11 = new TreeBuildNode<int>() { Data = 11, Colour = TreeNodeColor.Black };
            TreeBuildNode<int> node13 = new TreeBuildNode<int>() { Data = 13, Colour = TreeNodeColor.Black };
            TreeBuildNode<int> node15 = new TreeBuildNode<int>() { Data = 15, Colour = TreeNodeColor.Black };
            TreeBuildNode<int> node17 = new TreeBuildNode<int>() { Data = 17, Colour = TreeNodeColor.Red };
            TreeBuildNode<int> node22 = new TreeBuildNode<int>() { Data = 22, Colour = TreeNodeColor.Red };
            TreeBuildNode<int> node25 = new TreeBuildNode<int>() { Data = 25, Colour = TreeNodeColor.Black };
            TreeBuildNode<int> node27 = new TreeBuildNode<int>() { Data = 27, Colour = TreeNodeColor.Red };

            //13,6,1,11,17,15,25,22,27
            dlrList.AddRange(new List<TreeBuildNode<int>>(){
                node13,
                node6,
                node1,
                node11,
                node17,
                node15,
                node25,
                node22,
                node27
            });

            //1,6,11,13,15,17,22,25,27
            ldrList.AddRange(new List<TreeBuildNode<int>>()
            {
                node1,
                node6,
                node11,
                node13,
                node15,
                node17,
                node22,
                node25,
                node27
            });

            Tree<int>.BuildTree(tree, dlrList, ldrList);

            return tree;
        }
Example #27
0
        /// <summary>
        /// 构建测试树
        /// </summary>
        /// <returns></returns>
        static TestTree BuildTestTree()
        {
            TestTree tree = new TestTree();

            tree.Insert(8);
            tree.Insert(17);
            tree.Insert(25);
            tree.Insert(22);
            tree.Insert(15);
            tree.Insert(27);
            tree.Insert(13);
            tree.Insert(11);
            tree.Insert(6);
            tree.Insert(1);

            return tree;
        }
Example #28
0
        public void Test_Equal()
        {
            int      expectedNodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4;
            TestTree tree1 = new TestTree(expectedNodesCount);
            TestTree tree2 = new TestTree(expectedNodesCount);
            int      idx   = 0;

            CreateTestTree(tree1, idx, ref idx, 0, 3, 4);
            idx = 0;
            CreateTestTree(tree2, idx, ref idx, 0, 3, 4);

            CompareUFTrees <TestTree, TestTree> comp = new CompareUFTrees <TestTree, TestTree>();
            bool result = comp.Compare(tree1, tree2, (t1, t2, n) => t1.Nodes[n].Value == t2.Nodes[n].Value);

            Assert.IsTrue(result);
            Assert.AreEqual(CompareUFTrees.ResultKind.Equal, comp.Result);
        }
 public void Test()
 {
     TestTree t = new TestTree(2);
     t.Insert(2, 6, "A");
     t.Insert(2, 4, "B");
     t.Insert(2, 3, "C");
     t.Insert(2, 4, "D");
     t.Insert(0, 1, "E");
     t.Insert(2, 4, "F");
     t.Insert(5, 6, "G");
     t.Build();
     Assert.AreEqual(2, t.Root().Level);
     Assert.AreEqual(4, t.BoundablesAtLevel(0).Count);
     Assert.AreEqual(2, t.BoundablesAtLevel(1).Count);
     Assert.AreEqual(1, t.BoundablesAtLevel(2).Count);
     Assert.AreEqual(1, t.Query(0.5, 0.5).Count);
     Assert.AreEqual(0, t.Query(1.5, 1.5).Count);
     Assert.AreEqual(2, t.Query(4.5, 5.5).Count);
 }
Example #30
0
        public unsafe void Test_Simple()
        {
            TestTree tree = new TestTree(5);

            tree.SetDepth(0, 0);
            tree.Nodes[0].Id = 0;

            tree.SetDepth(1, 1);
            tree.Nodes[1].Id = 1;

            tree.SetDepth(2, 2);
            tree.Nodes[2].Id = 2;

            tree.SetDepth(3, 2);
            tree.Nodes[3].Id = 3;

            tree.SetDepth(4, 1);
            tree.Nodes[4].Id = 4;
        }
Example #31
0
        public void Test_StructureDiffers_DifferentNodesCount()
        {
            int      expectedNodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4;
            TestTree tree1 = new TestTree(expectedNodesCount);
            int      idx   = 0;

            CreateTestTree(tree1, idx, ref idx, 0, 3, 4);
            expectedNodesCount = 1 + 4 + 4 * 4;
            TestTree tree2 = new TestTree(expectedNodesCount);

            idx = 0;
            CreateTestTree(tree2, idx, ref idx, 0, 2, 4);

            CompareUFTrees <TestTree, TestTree> comp = new CompareUFTrees <TestTree, TestTree>();
            bool result = comp.Compare(tree1, tree2, (t1, t2, n) => t1.Nodes[n].Value == t2.Nodes[n].Value);

            Assert.IsFalse(result);
            Assert.AreEqual(CompareUFTrees.ResultKind.StructureDiffers, comp.Result);
            Assert.AreEqual(-1, comp.DiffersAt);
        }
Example #32
0
        public void Test()
        {
            var t = new TestTree(2);

            t.Insert(2, 6, "A");
            t.Insert(2, 4, "B");
            t.Insert(2, 3, "C");
            t.Insert(2, 4, "D");
            t.Insert(0, 1, "E");
            t.Insert(2, 4, "F");
            t.Insert(5, 6, "G");
            t.Build();
            Assert.AreEqual(2, t.Root().Level);
            Assert.AreEqual(4, t.BoundablesAtLevel(0).Count);
            Assert.AreEqual(2, t.BoundablesAtLevel(1).Count);
            Assert.AreEqual(1, t.BoundablesAtLevel(2).Count);
            Assert.AreEqual(1, t.Query(0.5, 0.5).Count);
            Assert.AreEqual(0, t.Query(1.5, 1.5).Count);
            Assert.AreEqual(2, t.Query(4.5, 5.5).Count);
        }
Example #33
0
        private static TestTree CreateTree2()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();
            TreeNode node4 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);
            node1.AppendChild(node4);

            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node2.AppendChild(node5);
            node4.AppendChild(node6);
            return(tree);
        }
Example #34
0
        public void ShouldIgnoreFile()
        {
            //TODO: figure out how to hook up gitignore
            var ignore = new GitIgnore();
            ignore.Excludes.Add("bin");
            ignore.Excludes.Add("obj");

            var root = new TestTree(null, "root")
            {
                new TestTreeEntry("hi"),
                new TestTreeEntry("obj", ObjectType.Tree)
                {
                    new TestTreeEntry("something.o")
                },
                new TestTreeEntry("bin", ObjectType.Tree)
                {
                    new TestTreeEntry("something.exe"),
                    new TestTreeEntry("something.pdb")
                },
                new TestTreeEntry("files", ObjectType.Tree)
                {
                    new TestTreeEntry("file1"),
                    new TestTreeEntry("file2")
                },
                new TestTreeEntry("readme.txt")
            };

            var expectedEntries = new[] { "files/file1", "files/file2", "root/hi", "root/readme.txt" };
            var i = 0;
            var items = root.EnumerateItems(true).ToArray();

            Assert.AreEqual(expectedEntries.Length, items.Length, "Number of Entries");
            foreach(var entry in items)
            {
                Assert.AreEqual(expectedEntries[i++], entry.FullName);
            }
        }
Example #35
0
        public override void Voxelize(World world)
        {
            // HERE: Fill the world with your data
            // Use world.SetBlock(), etc.
            // Beaware of the Bounds of the root node, which can be set in the NodeGraph Editor.
            // NO modifications outside the bound.

            int index;

            for (index = 0; index < (spline.Count - 1); index++)
            {
                TestTree.FillCyclinder(
                    world,
                    block,
                    spline[index].position,
                    spline[index + 1].position,
                    spline[index].radius,
                    spline[index + 1].radius,
                    spline[index].rotation * Vector3.up,
                    spline[index + 1].rotation * Vector3.up
                    );
                //break;
            }
        }
Example #36
0
        public void TreeHelper_Swap()
        {
            TestTree entity1 = new TestTree();
            TreeNode node1   = new TreeNode();

            entity1.SetRootNode(node1);
            TreeNode childNode1      = new TreeNode();
            TreeNode grandChildNode1 = new TreeNode();

            node1.AppendChild(childNode1);
            childNode1.AppendChild(grandChildNode1);

            TestTree entity2 = new TestTree();
            TreeNode node2   = new TreeNode();

            entity2.SetRootNode(node2);
            TreeNode childNode2      = new TreeNode();
            TreeNode grandChildNode2 = new TreeNode();

            node2.AppendChild(childNode2);
            childNode2.AppendChild(grandChildNode2);

            TreeHelper.Swap(entity1.RootNode, entity2.RootNode.ChildNodes[0]);

            Assert.Same(childNode2, entity1.RootNode);
            Assert.Null(childNode2.ParentNode);
            Assert.Same(entity1, childNode2.Tree);
            Assert.Same(entity1, grandChildNode2.Tree);

            Assert.Same(node2, entity2.RootNode);
            Assert.Same(node1, entity2.RootNode.ChildNodes[0]);
            Assert.Same(node2, node1.ParentNode);
            Assert.Same(entity2, node1.Tree);
            Assert.Same(entity2, childNode1.Tree);
            Assert.Same(entity2, grandChildNode1.Tree);
        }
Example #37
0
 public void Execute()
 {
     TestTree.Tick();
 }
Example #38
0
        private static void WLTree(TestTree tree)
        {
            int layout = 0;

            WLNode(layout, tree.Root);

            WL("--------------------------------------------------------------------");
        }
Example #39
0
        /// <summary>
        /// 输出两棵树的对比
        /// </summary>
        /// <param name="treeleft"></param>
        /// <param name="treeright"></param>
        private static void WLTrees(TestTree treeleft, TestTree treeright)
        {
            int layout = 0;

            WLNodes(layout, treeleft.Root, treeright.Root);

            WL("--------------------------------------------------------------------");
        }