Example #1
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());
        }
Example #2
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());
        }
Example #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);
        }
Example #4
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);
        }
Example #5
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");
        }