Exemple #1
0
        public void Test_SubGridTreeBitMask_GetCellAndSetCell(int x, int y)
        {
            var mask = new SubGridTreeBitMask();

            mask.GetCell(x, y).Should().BeFalse();
            mask.SetCell(x, y, true);
            mask.GetCell(x, y).Should().BeTrue();
            mask.SetCell(x, y, false);
            mask.GetCell(x, y).Should().BeFalse();
        }
Exemple #2
0
        public void Test_SubGridTreeBitMask_LeafExists_Negative()
        {
            var mask = new SubGridTreeBitMask();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask.SetCell(x, y, true);
                }
            }

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = (i + 1) * 1000000;
                    int y = (j + 1) * 1000000;

                    mask.LeafExists(x, y).Should().BeFalse();
                }
            }
        }
Exemple #3
0
        public void Test_SubGridTreeBitMask_ClearCellIfSet_SingleCellAtLocation(int x, int y)
        {
            var mask = new SubGridTreeBitMask();

            mask[x, y].Should().BeFalse();
            mask.ClearCellIfSet(x, y);
            mask[x, y].Should().BeFalse();

            mask.SetCell(x, y, true);
            mask[x, y].Should().BeTrue();

            mask.ClearCellIfSet(x, y);
            mask[x, y].Should().BeFalse();
        }
Exemple #4
0
        public void Test_SubGridTreeBitMask_SetOp_AND()
        {
            var mask = new SubGridTreeBitMask();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask.SetCell(x, y, true);
                }
            }

            int expectedBitCount = 10000;

            mask.CountBits().Should().Be(expectedBitCount);

            // Make a copy of mask
            var secondMask = new SubGridTreeBitMask();

            secondMask.SetOp_OR(mask);
            secondMask.CountBits().Should().Be(expectedBitCount);

            // Check ANDing mask and second mask results in the same bit count
            secondMask.SetOp_AND(mask);
            secondMask.CountBits().Should().Be(expectedBitCount);

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask[x, y].Should().BeTrue();
                }
            }

            // Check ANDing with empty mask clears all bits in mask
            var emptyMask = new SubGridTreeBitMask();

            emptyMask.CountBits().Should().Be(0);
            mask.SetOp_AND(emptyMask);

            mask.CountBits().Should().Be(0);
        }
Exemple #5
0
        public void Test_SubGridTreeBitMask_CountBits()
        {
            var mask = new SubGridTreeBitMask();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask.SetCell(x, y, true);
                }
            }

            mask.CountBits().Should().Be(10000);
        }
Exemple #6
0
        public void Test_SubGridTreeBitMask_SetOp_OR()
        {
            var mask = new SubGridTreeBitMask();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask.SetCell(x, y, true);
                }
            }

            int expectedBitCount = 10000;

            mask.CountBits().Should().Be(expectedBitCount);

            // Make a copy of mask
            var secondMask = new SubGridTreeBitMask();

            secondMask.SetOp_OR(mask);
            secondMask.CountBits().Should().Be(expectedBitCount);

            var thirdMask = new SubGridTreeBitMask();

            secondMask.SetOp_OR(thirdMask);
            secondMask.CountBits().Should().Be(expectedBitCount);

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    secondMask[x, y].Should().BeTrue();
                }
            }
        }
Exemple #7
0
        public void Test_SubGridTreeBitMask_ClearCellIfSet_ManyCellsWidelyDispersed()
        {
            var mask = new SubGridTreeBitMask();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    int x = i * 10;
                    int y = j * 10;

                    mask[x, y].Should().BeFalse();
                    mask.ClearCellIfSet(x, y);
                    mask[x, y].Should().BeFalse();

                    mask.SetCell(x, y, true);
                    mask[x, y].Should().BeTrue();

                    mask.ClearCellIfSet(x, y);
                    mask[x, y].Should().BeFalse();
                }
            }
        }