Beispiel #1
0
        public void Test_NodeSubGrid_WithinSparcityLimit()
        {
            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 sub grids to the parent
            for (int i = 0; i < sparcityLimit; 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);

            // Read through the sub grids added, plus another one to cover access failure
            for (int i = 0; i < sparcityLimit; i++)
            {
                var subGrid2 = parentSubgrid.GetSubGrid(i % SubGridTreeConsts.SubGridTreeDimension, i / SubGridTreeConsts.SubGridTreeDimension);
                subGrid2.Should().NotBeNull();
            }

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

            subGrid.Should().BeNull();

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

            parentSubgrid.CountNonNullCells().Should().Be(0);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }