Ejemplo n.º 1
0
        public void RTree_Insertion_Test()
        {
            var nodeCount      = 1000;
            var randomPolygons = new HashSet <Polygon>();

            for (int i = 0; i < nodeCount; i++)
            {
                randomPolygons.Add(getRandomPointOrPolygon());
            }
            var order = 5;
            var tree  = new RTree(order);

            int j = 0;

            foreach (var polygon in randomPolygons)
            {
                tree.Insert(polygon);

                //IEnumerable test
                Assert.AreEqual(tree.Count, tree.Count());
                //height should be similar to that of B+ tree.
                //https://en.wikipedia.org/wiki/B-tree#Best_case_and_worst_case_heights
                var theoreticalMaxHeight = Math.Ceiling(Math.Log((j + 2) / 2, (int)Math.Ceiling((double)order / 2))) + 1;

                var actualMaxHeight = tree.Root.Height;
                Assert.AreEqual(verifyHeightUniformityAndReturnHeight(tree.Root, order), actualMaxHeight);
                Assert.IsTrue(actualMaxHeight <= theoreticalMaxHeight);
                j++;

                Assert.IsTrue(tree.Exists(polygon));
            }

            Assert.AreEqual(j, tree.Count);
        }
        public void RTree_Deletion_Test()
        {
            var nodeCount      = 1000;
            var randomPolygons = new System.Collections.Generic.HashSet <Polygon>();

            for (int i = 0; i < nodeCount; i++)
            {
                randomPolygons.Add(getRandomPointOrPolygon());
            }
            var order = 5;
            var tree  = new RTree(order);

            foreach (var polygon in randomPolygons)
            {
                tree.Insert(polygon);
            }

            int j = randomPolygons.Count;

            foreach (var polygon in randomPolygons)
            {
                tree.Delete(polygon);
                Assert.IsFalse(tree.Exists(polygon));

                j--;

                if (j > 0)
                {
                    var actualMaxHeight = tree.Root.Height;
                    Assert.AreEqual(verifyHeightUniformityAndReturnHeight(tree.Root, order), actualMaxHeight);
                    Assert.AreEqual(j, tree.Count);
                }
            }
        }