Exemple #1
0
        private void GetTrailing()
        {
            IndexGenerator.BitString bs = new IndexGenerator.BitString();
            bs.AppendBits((byte)78);
            IndexGenerator.BitString bs2 = bs.GetTrailing(3);
            BitStringEquals(bs2, new byte[] { 6 });

            bs = new IndexGenerator.BitString();
            bs.AppendBits((byte)78);
            bs.AppendBits(unchecked ((byte)-5));
            bs2 = bs.GetTrailing(9);
            BitStringEquals(bs2, new byte[] { 78, 1 });

            bs2.AppendBits((byte)100);
            BitStringEquals(bs2, ByteUtils.ToBytes(new sbyte[] { 78, -55 }));
            bs = bs2.GetTrailing(13);
            BitStringEquals(bs, new byte[] { 78, 9 });
            bs2 = bs2.GetTrailing(11);
            BitStringEquals(bs2, new byte[] { 78, 1 });

            bs2.AppendBits((byte)100);
            BitStringEquals(bs2, new byte[] { 78, 33, 3 });
            bs2 = bs2.GetTrailing(16);
            BitStringEquals(bs2, new byte[] { 78, 33 });
        }
Exemple #2
0
        private void BitStringEquals(IndexGenerator.BitString bs, byte[] arr)
        {
            if (bs.Bytes.Length < arr.Length)
            {
                throw new Exception("BitString equality test failed!");
            }

            arr = arr.CopyOf(bs.Bytes.Length);
            if (!Compare.AreEqual(arr, bs.Bytes))
            {
                throw new Exception("BitString equality test failed!");
            }
        }
Exemple #3
0
 private void AppendBitsByteArray()
 {
     IndexGenerator.BitString bs = new IndexGenerator.BitString();
     bs.AppendBits((byte)78);
     BitStringEquals(bs, new byte[] { 78 });
     bs.AppendBits(unchecked ((byte)-5));
     BitStringEquals(bs, ByteUtils.ToBytes(new sbyte[] { 78, -5 }));
     bs.AppendBits((byte)127);
     BitStringEquals(bs, ByteUtils.ToBytes(new sbyte[] { 78, -5, 127 }));
     bs.AppendBits((byte)0);
     BitStringEquals(bs, ByteUtils.ToBytes(new sbyte[] { 78, -5, 127, 0 }));
     bs.AppendBits((byte)100);
     BitStringEquals(bs, ByteUtils.ToBytes(new sbyte[] { 78, -5, 127, 0, 100 }));
 }
Exemple #4
0
        private void GetLeadingAsInt()
        {
            IndexGenerator.BitString bs = new IndexGenerator.BitString();
            bs.AppendBits((byte)78);
            bs.AppendBits((byte)42);
            if (!Compare.Equals(1, bs.GetLeadingAsInt(3)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
            if (!Compare.Equals(84, bs.GetLeadingAsInt(9)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
            if (!Compare.Equals(338, bs.GetLeadingAsInt(11)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }

            IndexGenerator.BitString bs2 = bs.GetTrailing(11);
            BitStringEquals(bs2, new byte[] { 78, 2 });
            if (!Compare.Equals(590, bs2.GetLeadingAsInt(11)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
            if (!Compare.Equals(9, bs2.GetLeadingAsInt(5)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }

            bs2.AppendBits((byte)115);
            if (!Compare.Equals(230, bs2.GetLeadingAsInt(9)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
            if (!Compare.Equals(922, bs2.GetLeadingAsInt(11)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
            bs2.AppendBits(unchecked ((byte)-36));
            if (!Compare.Equals(55, bs2.GetLeadingAsInt(6)))
            {
                throw new Exception("BitString LeadingAsInt test failed!");
            }
        }