Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public void OrderStatisticTreeTests_FindTheKthSmallestNode2()
        {
            IOrderStatisticTree <int, string> tree = new OrderStatisticTree <int, string>();

            var actualNode = tree.FindTheKthSmallestNode(0);

            Assert.IsNull(actualNode);
        }
Exemplo n.º 3
0
        public void OrderStatisticTreeTests_FindTheKthSmallestNode2()
        {
            IOrderStatisticTree<int, string> tree = new OrderStatisticTree<int, string>();

            var actualNode = tree.FindTheKthSmallestNode(0);

            Assert.IsNull(actualNode);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
            }
        }