コード例 #1
0
        public void OrderStatisticTreeTests_Random_FindTheKthSmallestNode()
        {
            Random r = new Random();
            int    n = r.Next(10000) + 1;

            IOrderStatisticTree <int, string>           tree = new OrderStatisticTree <int, string>();
            List <IBinarySearchTreeNode <int, string> > list = new List <IBinarySearchTreeNode <int, string> >();

            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                list.Add(tree.Insert(key, string.Empty));
            }

            list.Sort(new Comparison <IBinarySearchTreeNode <int, string> >((x, y) => x.Key.CompareTo(y.Key)));

            for (int i = 0; i < n / 2; i++)
            {
                int request = r.Next(n);

                var expectedNode = list[request];

                var actualNode = tree.FindTheKthSmallestNode(request);

                Assert.IsNotNull(actualNode);
                Assert.AreEqual(expectedNode, actualNode);
            }
        }
コード例 #2
0
        public void OrderStatisticTreeTests_FindTheKthSmallestNode4()
        {
            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();
            tree.Insert(10, "John");
            tree.Insert(5, "Clark");
            tree.Insert(13, "Pitty");
            var expectedNode = tree.Insert(17, "Lilly");
            tree.Insert(8, "Jack");
            tree.Insert(0, "Lui");
            tree.Insert(16, "Petr");

            var actualNode = tree.FindTheKthSmallestNode(6);

            Assert.IsNotNull(actualNode);
            Assert.AreEqual(expectedNode, actualNode);
        }
コード例 #3
0
        public void OrderStatisticTreeTests_FindTheKthSmallestNode3()
        {
            IOrderStatisticTree <int, string> tree = new OrderStatisticTree <int, string>();
            var expectedNode = tree.Insert(10, "John");

            tree.Insert(5, "Clark");
            tree.Insert(13, "Pitty");
            tree.Insert(17, "Lilly");
            tree.Insert(8, "Jack");
            tree.Insert(0, "Lui");
            tree.Insert(16, "Petr");

            var actualNode = tree.FindTheKthSmallestNode(3);

            Assert.IsNotNull(actualNode);
            Assert.AreEqual(expectedNode, actualNode);
        }
コード例 #4
0
        public void OrderStatisticTreeTests_GetRank2()
        {
            IOrderStatisticTree <int, string> tree = new OrderStatisticTree <int, string>();

            tree.Insert(10, "John");
            tree.Insert(5, "Clark");
            var node = tree.Insert(13, "Pitty");

            tree.Insert(17, "Lilly");
            tree.Insert(8, "Jack");
            tree.Insert(0, "Lui");
            tree.Insert(16, "Petr");

            var actualRank = tree.GetRank((IOrderStatisticTreeNode <int, string>)node);

            Assert.IsTrue(actualRank == 4);
        }
コード例 #5
0
        public void OrderStatisticTreeTests_Random_GetRank2()
        {
            Random r = new Random();
            int    n = r.Next(1000000) + 1;

            IOrderStatisticTree <int, string> tree = new OrderStatisticTree <int, string>();

            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                tree.Insert(key, string.Empty);
            }

            var list = tree.TraverseInOrder().ToList();

            for (int i = 0; i < n; i++)
            {
                var actualRank = tree.GetRank((IOrderStatisticTreeNode <int, string>)list[i]);

                Assert.AreEqual(actualRank, i);
            }
        }
コード例 #6
0
        public void OrderStatisticTreeTests_GetRank2()
        {
            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();
            tree.Insert(10, "John");
            tree.Insert(5, "Clark");
            var node = tree.Insert(13, "Pitty");
            tree.Insert(17, "Lilly");
            tree.Insert(8, "Jack");
            tree.Insert(0, "Lui");
            tree.Insert(16, "Petr");

            var actualRank = tree.GetRank((IOrderStatisticTreeNode<int, string>)node);

            Assert.IsTrue(actualRank == 4);
        }
コード例 #7
0
        public void OrderStatisticTreeTests_Random_GetRank2()
        {
            Random r = new Random();
            int n = r.Next(1000000) + 1;

            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();
            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                tree.Insert(key, string.Empty);
            }

            var list = tree.TraverseInOrder().ToList();

            for (int i = 0; i < n; i++)
            {
                var actualRank = tree.GetRank((IOrderStatisticTreeNode<int, string>)list[i]);

                Assert.AreEqual(actualRank, i);
            }
        }
コード例 #8
0
        public void OrderStatisticTreeTests_Random_FindTheKthSmallestNode()
        {
            Random r = new Random();
            int n = r.Next(10000) + 1;

            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();
            List<IBinarySearchTreeNode<int, string>> list = new List<IBinarySearchTreeNode<int, string>>();
            for (int i = 0; i < n; i++)
            {
                int key = r.Next(int.MaxValue);
                list.Add(tree.Insert(key, string.Empty));
            }

            list.Sort(new Comparison<IBinarySearchTreeNode<int, string>>((x, y) => x.Key.CompareTo(y.Key)));

            for (int i = 0; i < n / 2; i++)
            {
                int request = r.Next(n);

                var expectedNode = list[request];

                var actualNode = tree.FindTheKthSmallestNode(request);

                Assert.IsNotNull(actualNode);
                Assert.AreEqual(expectedNode, actualNode);
            }
        }