Пример #1
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");
        }
Пример #2
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);
        }
Пример #3
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);
        }