Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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);
     }
 }