Beispiel #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);
        }
Beispiel #2
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());
            }
        }
Beispiel #3
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);
            }
        }