コード例 #1
0
        public void Test_ValueDiffers()
        {
            int       nodeCount;
            TestNode1 root1;

            nodeCount = 0;
            CreateTestTree1(out root1, 4, 2, ref nodeCount);
            TestNode2 root2;

            nodeCount = 0;
            CreateTestTree2(out root2, 4, 2, ref nodeCount);

            root2.Children[1].Children[0].DoubleValue = -1; // Change the value

            CompareTrees <TestNode1, TestNode1, int, TestNode2, TestNode2, int> comp =
                new CompareTrees <TestNode1, TestNode1, int, TestNode2, TestNode2, int>();
            bool result = comp.Compare(root1, root1, root2, root2, (t1, n1, t2, n2) => n1.IntValue == n2.DoubleValue);

            Assert.IsFalse(result);
            Assert.AreEqual(CompareTrees.ResultKind.ValueDiffers, comp.Result);
            Assert.AreEqual(9, comp.DiffersAt);

            // Test helper functions as well.
            result = CompareTrees <int, int> .Compare(root1, root1, root2, root2, (t1, n1, t2, n2) => n1.IntValue == n2.DoubleValue);

            Assert.IsFalse(result);

            result = CompareTrees <int, int> .Compare(root1, root1, root2, root2);

            Assert.IsFalse(result);
        }
コード例 #2
0
        public void Test_ReadWrite()
        {
            ClusterTree rt1  = new ClusterTree();
            RangeNode   root = new RangeNode(5);

            rt1.Root = root;
            for (int i = 0; i < 5; ++i)
            {
                root.Children[i] = new RangeNode(0)
                {
                    UpperLimit = 0.1f * i
                };
            }
            rt1.Version.UserDescription = "Bla bla";

            string fileName = Path.Combine(_outDir, "ClusterTree.dat");

            rt1.Write(fileName);
            ClusterTree rt2 = ClusterTree.Read(fileName);

            Assert.AreEqual(rt1.Version, rt2.Version);
            Assert.IsTrue(CompareTrees <int, int> .Compare(rt1, rt1.Root, rt2, rt2.Root,
                                                           (t1, n1, t2, n2) =>
            {
                return(((RangeNode)n1).UpperLimit == ((RangeNode)n2).UpperLimit);
            }));
        }
コード例 #3
0
        public void Test_Equal()
        {
            int       nodeCount;
            TestNode1 root1;

            nodeCount = 0;
            CreateTestTree1(out root1, 4, 3, ref nodeCount);
            TestNode2 root2;

            nodeCount = 0;
            CreateTestTree2(out root2, 4, 3, ref nodeCount);

            CompareTrees <TestNode1, TestNode1, int, TestNode2, TestNode2, int> comp =
                new CompareTrees <TestNode1, TestNode1, int, TestNode2, TestNode2, int>();
            bool result = comp.Compare(root1, root1, root2, root2, (t1, n1, t2, n2) => n1.IntValue == n2.DoubleValue);

            Assert.IsTrue(result);
            Assert.AreEqual(CompareTrees.ResultKind.Equal, comp.Result);

            // Test helper functions as well.
            result = CompareTrees <int, int> .Compare(root1, root1, root2, root2, (t1, n1, t2, n2) => n1.IntValue == n2.DoubleValue);

            Assert.IsTrue(result);

            result = CompareTrees <int, int> .Compare(root1, root1, root2, root2);

            Assert.IsTrue(result);
        }