public void QuadrantsJoinWhenAtLowCapacity() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(1, 10, 25); List <ConcurrentGeoQuadtree <object> .IElement> elements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 20; ++i) { elements.Add(quadtree.InsertElement(null, new GeoCoordinates(0, 0))); } Assert.Equal(0, quadtree.GetLargestSubdivisionLevel()); quadtree.EfficientlyReindex(); int prevSubdivLevel = quadtree.GetLargestSubdivisionLevel(); Assert.True(prevSubdivLevel >= 1); foreach (var element in elements) { quadtree.RemoveElement(element); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() < prevSubdivLevel); }
public void QuadrantDoesntJoinIfWouldBeAboveCapacity() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(2, 10, 25); List <ConcurrentGeoQuadtree <object> .IElement> elements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 10; ++i) { elements.Add(quadtree.InsertElement(null, new GeoCoordinates(1, 1))); } for (int i = 0; i < 10; ++i) { quadtree.InsertElement(null, new GeoCoordinates(-1, -1)); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() >= 1); // Remove all but one element from the top-right quadrant but not the // bottom-left quadrant. foreach (var element in elements.Take(9)) { quadtree.RemoveElement(element); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() >= 1); }
public void QuadrantsSubdivideAfterPassingMaxCapacity() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(1, 10, 25); Assert.Equal(0, quadtree.GetLargestSubdivisionLevel()); for (int i = 0; i < 20; ++i) { quadtree.InsertElement(null, new GeoCoordinates(0, 0)); } quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() > 0); }
public void QuadrantsContinueSubdividingAfterCapacityEvenWhenNoInsert() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(1, 10, 25); for (int i = 0; i < 20; ++i) { quadtree.InsertElement(null, new GeoCoordinates(0, 0)); } Assert.Equal(0, quadtree.GetLargestSubdivisionLevel()); for (int i = 0; i < 10; ++i) { quadtree.EfficientlyReindex(); Assert.True(quadtree.GetLargestSubdivisionLevel() > i); } }