Example #1
0
        public void SetRandomBitsTest()
        {
            var barr = new FastBitArray(new byte[0]);

            barr.Length = 150;
            var values  = new List <int>();
            var lengths = new List <int>();
            var rnd     = new Random();
            var pos     = 0;

            for (int i = 0; i < 10; i++)
            {
                var val = rnd.Next();
                var len = rnd.Next(1, 20);
                barr.SetBits(pos, (ulong)val, len);

                values.Add(val);
                lengths.Add(len);
                pos += len;
            }

            pos = 0;
            for (int i = 0; i < 10; i++)
            {
                var len           = lengths[i];
                var expectedValue = values[i];
                var value         = barr.GetBits(pos, len);
                Assert.Equal(((ulong)expectedValue & value), value);
                pos += len;
            }
        }
Example #2
0
        public void SetBitsBigEndianTest()
        {
            var barr = new FastBitArray(new byte[0]);

            barr.Length = 5;
            barr.SetBits(0, 14, 4);
            var val = barr.GetBits(0, 4);

            barr        = new FastBitArray(new byte[0]);
            barr.Length = 5;
            barr.SetBit(0, false);
            barr.SetBit(1, true);
            barr.SetBit(2, true);
            barr.SetBit(3, true);
            val = barr.GetBits(0, 4);
        }