Exemple #1
0
        public void Test_NodeSubGrid_ScanSubGrids_TerminateProcessing()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill all of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            int leafCount = 0, nodeCount = 0;

            parentSubgrid.ScanSubGrids(tree.FullCellExtent(),
                                       leafSubgrid =>
            {
                leafCount++;
                return(true);
            },
                                       nodeSubgrid =>
            {
                nodeCount++;
                return(SubGridProcessNodeSubGridResult.TerminateProcessing);
            });

            Assert.Equal(0, leafCount);
            Assert.Equal(1, nodeCount);
        }
Exemple #2
0
        public void Test_NodeSubGrid_Creation()
        {
            SubGridTree  tree    = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);

            Assert.NotNull(subgrid);
        }
Exemple #3
0
        public void Test_NodeSubGrid_ExceedSparcityLimit()
        {
            var tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            var parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);
            var sparcityLimit = NodeSubGrid.SubGridTreeNodeCellSparcityLimit;

            // Add sparcity limit + 1 child node subgrids to the parent
            for (int i = 0; i < sparcityLimit + 1; i++)
            {
                var subgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
                parentSubgrid.SetSubGrid(i % SubGridTreeConsts.SubGridTreeDimension, i / SubGridTreeConsts.SubGridTreeDimension, subgrid);
            }

            parentSubgrid.CountNonNullCells().Should().Be((int)sparcityLimit + 1);

            // Read through the sub grids added, plus another one rto cover access failure
            for (int i = 0; i < sparcityLimit + 2; i++)
            {
                var subgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);

                subgrid.Should().NotBeNull();
            }

            var subGrid = parentSubgrid.GetSubGrid((int)(sparcityLimit + 2) % SubGridTreeConsts.SubGridTreeDimension, (int)(sparcityLimit + 2) / SubGridTreeConsts.SubGridTreeDimension);

            subGrid.Should().BeNull();

            // Drain the sub grids back out of the node
            for (int i = 0; i < sparcityLimit + 1; i++)
            {
                parentSubgrid.SetSubGrid(i % SubGridTreeConsts.SubGridTreeDimension, i / SubGridTreeConsts.SubGridTreeDimension, null);
            }

            parentSubgrid.CountNonNullCells().Should().Be(0);
        }
Exemple #4
0
        public void Test_NodeSubGrid_ForEachSubgrid_SpatialSubsetScans()
        {
            int          count;
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill all of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            // Iterate over a subset of the subgrids counting them (from the cell at (10, 10) to the cell at (29, 29)
            // an interval of 20 cells in the X and Y dimensions
            count = 0;
            parentSubgrid.ForEachSubGrid(x =>
            {
                count++;
                return(SubGridProcessNodeSubGridResult.OK);
            }, 10, 10, 29, 29); // ==> Should scan 400 cells

            Assert.Equal(400, count);
        }
Exemple #5
0
        public void Test_NodeSubGrid_IsEmpty()
        {
            SubGridTree  tree    = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);

            Assert.True(subgrid.IsEmpty(), "Node subgrid not empty after creation");
            Assert.Equal(0, subgrid.CountChildren());
        }
Exemple #6
0
        public void Test_SubGrid_ToString()
        {
            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            var child  = new NodeSubGrid(tree, null, 3); // create a node to be a child of the root node
            var parent = new NodeSubGrid(tree, null, 2); // create a node to be a child of the root node

            parent.SetSubGrid(0, 0, child);

            child.ToString().Should().Be($"Level:{3}, OriginX:{child.OriginX}, OriginY:{child.OriginY}");
        }
Exemple #7
0
        public void Test_NodeSubGrid_ForEachSubgrid_NodeFunctorWithIndices_InvalidCellRange()
        {
            SubGridTree  tree    = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subGrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);

            Action act = () => subGrid.ForEachSubGrid((x, y, s) => SubGridProcessNodeSubGridResult.TerminateProcessing, SubGridTreeConsts.SubGridTreeDimension, 0, 2 * SubGridTreeConsts.SubGridTreeDimension, 2 * SubGridTreeConsts.SubGridTreeDimension);

            act.Should().Throw <ArgumentException>().WithMessage("Minimum sub grid cell X/Y bounds are out of range");

            act = () => subGrid.ForEachSubGrid((x, y, s) => SubGridProcessNodeSubGridResult.TerminateProcessing, 0, SubGridTreeConsts.SubGridTreeDimension, 2 * SubGridTreeConsts.SubGridTreeDimension, 2 * SubGridTreeConsts.SubGridTreeDimension);
            act.Should().Throw <ArgumentException>().WithMessage("Minimum sub grid cell X/Y bounds are out of range");
        }
Exemple #8
0
        public void Test_NodeSubGrid_SetSubGrid_Sparcity_SetNullSubGridWithSingleExistingChild()
        {
            var tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            var parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);
            var subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);

            parentSubgrid.SetSubGrid(0, 0, subgrid);
            parentSubgrid.GetSubGrid(0, 0).Should().NotBeNull();

            // Test setting an existing null entry to null when there are non-zero entries in sparcity list
            parentSubgrid.SetSubGrid(1, 1, null);
        }
Exemple #9
0
        public void Test_NodeSubGrid_GetSubGrid()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            parentSubgrid.SetSubGrid(1, 1, subgrid);
            Assert.Equal(1, parentSubgrid.CountChildren());

            // Get the subgrid and verify it is the same as the one set into it
            Assert.Equal(parentSubgrid.GetSubGrid(1, 1), subgrid);
        }
Exemple #10
0
        public void Test_NodeSubGrid_CellHsValue()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            Assert.True(subgrid.IsEmpty(), "Node subgrid not empty after creation");
            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid not empty after creation");

            parentSubgrid.SetSubGrid(0, 0, subgrid);
            Assert.True(parentSubgrid.CellHasValue(0, 0), "Cell at 0, 0 does not indicate it has a value");
            Assert.False(parentSubgrid.CellHasValue(0, 1), "Cell at 0, 1 does indicate it has a value");
        }
Exemple #11
0
        public void Test_SubGrid_SetAbsoluteLevel_FailWithNonNullParent()
        {
            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            var child  = new NodeSubGrid(tree, null, 3); // create a node to be a child of the root node
            var parent = new NodeSubGrid(tree, null, 2); // create a node to be a child of the root node

            // Test setting level for unattached subgrid (even though we set it in the constructor above
            parent.SetSubGrid(0, 0, child);

            Action act = () => child.SetAbsoluteLevel(3);

            act.Should().Throw <TRexSubGridTreeException>().WithMessage("Nodes referencing parent nodes may not have their level modified");
        }
Exemple #12
0
        public void Test_NodeSubGrid_CountChildren()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid is empty after adding subgrids to parent");

            Assert.Equal(0, parentSubgrid.CountChildren());

            parentSubgrid.SetSubGrid(0, 0, subgrid);

            Assert.Equal(1, parentSubgrid.CountChildren());
        }
Exemple #13
0
        public void Test_NodeSubGrid_Clear_Single()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            Assert.True(subgrid.IsEmpty(), "Node subgrid not empty after creation");
            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid not empty after creation");

            parentSubgrid.SetSubGrid(0, 0, subgrid);
            Assert.False(parentSubgrid.IsEmpty(), "Parent node subgrid is empty after adding subgrid to parent");

            parentSubgrid.Clear();
            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid not empty after calling Clear()");
        }
Exemple #14
0
        public void Test_NodeSubGrid_SetSubgrid()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill the entirety of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            Assert.False(parentSubgrid.IsEmpty(), "Parent node subgrid is empty after adding subgrids to parent");
            Assert.Equal((int)parentSubgrid.CountChildren(), SubGridTreeConsts.CellsPerSubGrid);
        }
Exemple #15
0
        public void Test_SubGrid_RemoveFromParent()
        {
            // This can't be tested fully as the entire Set/Get subgrid functionality is abstract at this point, and
            // RemoveFromParent is part of that abstract workflow. At this level, we will test that no exception occurs
            // if the parent relationship is null

            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            var parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            var leafSubgrid   = new LeafSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels);

            parentSubgrid.SetSubGrid(0, 0, leafSubgrid);

            leafSubgrid.RemoveFromParent();
            leafSubgrid.Parent.Should().BeNull();
        }
Exemple #16
0
        public void Test_NodeSubGrid_ScanSubGrids()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill all of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            // Test all child subgrids are visited (count should be zero as there are no leaf subgrids
            int leafCount, nodeCount;

            leafCount = 0;
            parentSubgrid.ScanSubGrids(tree.FullCellExtent(),
                                       leafSubgrid =>
            {
                leafCount++;
                return(true);
            },
                                       null);
            Assert.Equal(0, leafCount);

            // Test all node child subgrids are visited (count should be zero as there are no leaf subgrids)
            leafCount = 0;
            nodeCount = 0;
            parentSubgrid.ScanSubGrids(tree.FullCellExtent(),
                                       leafSubgrid =>
            {
                leafCount++;
                return(true);
            },
                                       nodeSubgrid =>
            {
                nodeCount++;
                return(SubGridProcessNodeSubGridResult.OK);
            });
            Assert.Equal(0, leafCount);

            // Note, count is 1025 as the parent node counts as a node subgrid that was visited
            Assert.Equal(nodeCount, (1 + 1024));
        }
Exemple #17
0
        public void Test_NodeSubGrid_Clear_Many()
        {
            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid not empty after creation");

            // Fill the entirety of the parent subgrid with new child subgrids
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            Assert.False(parentSubgrid.IsEmpty(), "Parent node subgrid is empty after adding subgrids to parent");

            parentSubgrid.Clear();
            Assert.True(parentSubgrid.IsEmpty(), "Parent node subgrid not empty after calling Clear() to remove all subgrids");
        }
Exemple #18
0
        public void Test_NodeSubGrid_ForEachSubgrid_FullScans()
        {
            int          count;
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid subgrid       = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1);
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill half of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid / 2; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            // Iterate over all subgrids counting them
            count = 0;
            parentSubgrid.ForEachSubGrid(x =>
            {
                count++;
                return(SubGridProcessNodeSubGridResult.OK);
            });

            Assert.Equal((int)count, SubGridTreeConsts.CellsPerSubGrid / 2);

            // Fill all of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            // Iterate over all subgrids counting them
            count = 0;
            parentSubgrid.ForEachSubGrid(x =>
            {
                count++;
                return(SubGridProcessNodeSubGridResult.OK);
            });

            Assert.Equal((int)count, SubGridTreeConsts.CellsPerSubGrid);
        }
Exemple #19
0
        public void Test_NodeSubGrid_DeleteSubGrid()
        {
            SubGridTree  tree          = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());
            INodeSubGrid parentSubgrid = new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 2);

            // Fill the entirety of the parent subgrid with new child subgrids using SetSubGrid
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.SetSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension),
                                         new NodeSubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels - 1));
            }

            // Iterate over all subgrids deleting them one at a time
            for (int i = 0; i < SubGridTreeConsts.CellsPerSubGrid; i++)
            {
                parentSubgrid.DeleteSubGrid((byte)(i / SubGridTreeConsts.SubGridTreeDimension), (byte)(i % SubGridTreeConsts.SubGridTreeDimension));
            }

            Assert.Equal(0, parentSubgrid.CountChildren());
            Assert.True(parentSubgrid.IsEmpty(), "Parent not empty after deletion of subgrids");
        }