Ejemplo n.º 1
0
        private static bool ClearBitAndVerify(CompressedBitmapBuilder builder, SuperSlowUncompressedBitmap witness, int offset)
        {
            Console.WriteLine();
            Console.WriteLine("Clear({0}):", offset);
            bool actual   = builder.Clear(offset);
            bool expected = witness.Clear(offset);

            Assert.That(actual, Is.EqualTo(expected), "Clear({0})", offset);

            Verify(builder, witness);
            return(actual);
        }
Ejemplo n.º 2
0
        public void Test_CompressedBitmapBuilder_Random_Sets_And_Clears()
        {
            // randomly alternate between setting and clearing random bits

            int K = 20;
            int S = 100;
            int C = 100;
            int N = 5 * 1000;

            var bmp = CompressedBitmap.Empty;

            var witness = new SuperSlowUncompressedBitmap();

            var rnd = new Random(12345678);

            for (int k = 0; k < K; k++)
            {
                Console.WriteLine("### Generation " + k);

                // convert to builder
                var builder = bmp.ToBuilder();
                Verify(builder, witness);

                // set S bits
                for (int i = 0; i < S; i++)
                {
                    int p = rnd.Next(N);
                    builder.Set(p);
                    witness.Set(p);
                    //SetBitAndVerify(builder, witness, p);
                }

                // clear C bits
                for (int i = 0; i < C; i++)
                {
                    int p = rnd.Next(N);
                    //ClearBitAndVerify(builder, witness, p);
                    builder.Clear(p);
                    witness.Clear(p);
                }

                // pack back to bitmap
                bmp = builder.ToBitmap();
                Console.WriteLine();
                Console.WriteLine("> Result of gen #{0}: {1}", k, bmp.Dump());
                Console.WriteLine("> " + bmp.ToSlice().ToHexaString());
                Console.WriteLine();
            }
        }