示例#1
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);
        }
示例#2
0
        public void ReconstructionTest()
        {
            var arr  = new byte[] { 1, 2, 3, 4 };
            var b    = new FastBitArray(arr);
            var arr2 = b.ToByteArray();

            Assert.Equal(arr.Length, arr2.Length);
            Assert.Equal(arr[0], arr2[0]);
            Assert.Equal(arr[arr.Length - 1], arr2[arr2.Length - 1]);
            Assert.Equal(4 * 8, b.Length);

            b.Length++;
            Assert.Equal((4 * 8) + 1, b.Length);
            arr2 = b.ToByteArray();
            Assert.Equal(arr[0], arr2[0]);
            Assert.Equal(0, arr2[arr2.Length - 1]);
            b.SetBit(4 * 8, true);
            arr2 = b.ToByteArray();
            Assert.Equal(arr[0], arr2[0]);
            Assert.Equal(1, arr2[arr2.Length - 1]);

            var b2   = new FastBitArray(arr2);
            var arr3 = b2.ToByteArray();

            Assert.Equal(arr2.Length, arr3.Length);
            Assert.Equal(arr2[0], arr3[0]);
            Assert.Equal(arr2[arr2.Length - 1], arr3[arr3.Length - 1]);
        }
示例#3
0
        public void SetBitAndGetBitsTest()
        {
            var barr = new FastBitArray(new byte[0]);

            barr.Length = 150;

            var j = true;

            for (int i = 0; i < 64; i += 2)
            {
                if (j)
                {
                    barr.SetBit(i, true);
                    barr.SetBit(i + 1, true);
                }
                else
                {
                    barr.SetBit(i, false);
                    barr.SetBit(i + 1, false);
                }

                j = !j;
            }

            for (var i = 0; i < 16; i++)
            {
                Assert.Equal(0b11UL, barr.GetBits(i * 4, 2));
                Assert.Equal(0b00UL, barr.GetBits((i * 4) + 2, 2));
            }

            for (var i = 0; i < 8; i++)
            {
                Assert.Equal(0b0011UL, barr.GetBits(i * 8, 4));
                Assert.Equal(0b0011UL, barr.GetBits((i * 8) + 4, 2));
            }

            Assert.Equal(0b11001UL, barr.GetBits(29, 5));
        }