Esempio n. 1
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_ForEach_Action()
        {
            // Test iteration action for empty, full and arbitrary masks
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Filled);

            int sum;

            sum = 0;
            bits.ForEach((x, y) => { if (bits.BitSet(x, y))
                                     {
                                         sum++;
                                     }
                         });
            Assert.True(sum == bits.CountBits() && sum == SubGridTreeConsts.CellsPerSubGrid, "Summation via ForEach on full mask did not give expected result");

            sum = 0;
            bits.Clear();
            bits.ForEach((x, y) => { if (bits.BitSet(x, y))
                                     {
                                         sum++;
                                     }
                         });
            Assert.True(sum == bits.CountBits() && sum == 0, "Summation via ForEach on empty mask did not give expected result");

            sum = 0;
            bits.SetBit(1, 1);
            bits.ForEach((x, y) => { if (bits.BitSet(x, y))
                                     {
                                         sum++;
                                     }
                         });
            Assert.True(sum == bits.CountBits() && sum == 1, "Summation via ForEach on mask with single bit set at (1, 1) did not give expected result");
        }
Esempio n. 2
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_ClearBit()
        {
            // Test setting a bit on and off, at two corners to test boundary conditions
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            bits.SetBit(0, 0);

            Assert.NotEqual(0U, bits.Bits[0]);
            Assert.Equal(1, bits.CountBits());

            bits.ClearBit(0, 0);

            Assert.Equal(0U, bits.Bits[0]);
            Assert.Equal(0, bits.CountBits());

            bits.SetBit(31, 31);

            Assert.NotEqual(0U, bits.Bits[31]);
            Assert.Equal(1, bits.CountBits());

            bits.ClearBit(31, 31);

            Assert.Equal(0U, bits.Bits[31]);
            Assert.Equal(0, bits.CountBits());
        }
Esempio n. 3
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_CountBits()
        {
            SubGridTreeBitmapSubGridBits bits = SubGridTreeBitmapSubGridBits.FullMask;

            Assert.Equal(bits.CountBits(), SubGridTreeConsts.CellsPerSubGrid);

            bits.Clear();
            Assert.Equal(0, bits.CountBits());

            bits.SetBit(1, 1);
            Assert.Equal(1, bits.CountBits());
        }
Esempio n. 4
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_ForEach_Function()
        {
            // Test iteration function for empty, full and arbitrary masks
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            bits.ForEach((x, y) => { return(true); });
            Assert.Equal(bits.CountBits(), SubGridTreeConsts.CellsPerSubGrid);

            bits.Clear();
            bits.ForEach((x, y) => { return(x < 16); });
            Assert.Equal(bits.CountBits(), SubGridTreeConsts.CellsPerSubGrid / 2);

            bits.Clear();
            bits.ForEach((x, y) => { return((x == 1) && (y == 1)); });
            Assert.Equal(1, bits.CountBits());
        }
Esempio n. 5
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_Serialisation_Arbitrary()
        {
            // Test serialisation with arbitrary bits set
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            bits.SetBit(0, 0);
            bits.SetBit(10, 10);
            bits.SetBit(20, 20);
            bits.SetBit(31, 31);

            MemoryStream ms = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8, true);

            bits.Write(bw);
            BinaryReader br = new BinaryReader(ms, Encoding.UTF8, true);

            ms.Position = 0;

            SubGridTreeBitmapSubGridBits bits2 = SubGridTreeBitmapSubGridBits.FullMask;

            bits2.Read(br);

            Assert.True(bits.Equals(bits2), "Bits not equal after serialisation with arbitrary mask");
            Assert.Equal(4, bits.CountBits());
        }