示例#1
0
        public void TestGetBytes()
        {
            for (int i = 0; i < 20; i++)
            {
                BitBuffer b = new BitBuffer(new byte[256], i);
                Random    r = new Random(0);
                for (int j = 0; j < 15; j++)
                {
                    int expected = r.Next();
                    b.Put(expected);
                    Assert.AreEqual(expected, b.GetIntAt(32 * j));
                }

                for (int k = 0; k < 20; k++)
                {
                    byte[] clon = new byte[256];
                    b.GetBitsAt(0, clon, k, 700);
                    BitBuffer b2 = new BitBuffer(clon);

                    r = new Random(0);
                    for (int j = 0; j < 15; j++)
                    {
                        uint expected = ((uint)r.Next()) << k;
                        uint read     = b2.GetUInt(32) & (~0u << k);
                        Assert.AreEqual(expected, read, "offset source=" + i + ", ofset destination=" + k + ", number=" + j);
                    }
                }
            }
        }