Beispiel #1
0
        public void Ext_ULong_AddGet_BitsMinMax_InOut()
        {
            int     maxBits = 64;
            BVector d       = new BVector();
            ulong   value;
            ulong   val;
            ulong   expected;
            ulong   maxVal = ulong.MaxValue;
            byte    bits;


            // add min and max values for 2-32 bits
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits  = (byte)(maxBits - i);
                value = maxVal >> i;
                // add max
                d.Add(value, bits);
            }

            // add min and max values for 2-32 bits seperated by 1 bit
            d.Add1(false);
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits  = (byte)(maxBits - i);
                value = maxVal >> i;
                // add max
                d.Add(value, bits);
                d.Add1(false);
            }

            BVector d2 = new BVector(d.ToBytes());

            // get min and max values for 2-32 bits
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits = (byte)(maxBits - i);

                // get max
                expected = maxVal >> i;
                val      = d2.GetULong(bits);
                Assert.AreEqual(expected, val);
            }

            // get min and max values for 2-32 bits seperated by 1 bit
            Assert.AreEqual(false, d2.Get1());
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits = (byte)(maxBits - i);

                // get max
                expected = maxVal >> i;
                val      = d2.GetULong(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());
            }
        }
Beispiel #2
0
        public void Ext_ULong_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add(0, 32);
            d.GetULong(1);
        }
Beispiel #3
0
        public void Ext_ULong_Get_Exc_MoreThan32Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add(0, 32);
            d.GetULong(65);
        }
Beispiel #4
0
        public void Ext_ULong_AddGet_Rnd_InOut()
        {
            BVector      d           = new BVector();
            var          rnd         = new CryptoRandom();
            List <ulong> values      = new List <ulong>();
            int          maxBits     = 64;
            int          index       = 0;
            int          itemsPerBit = 100;
            ulong        value;
            ulong        val;
            ulong        expected;
            long         maxVal = long.MaxValue;
            long         tmp;
            byte         bits;


            // add random values for 2-32 bits
            for (int j = 0; j < itemsPerBit; j++)
            {
                for (int i = 0; i < (maxBits - 2); i++)
                {
                    bits = (byte)(maxBits - i);
                    tmp  = maxVal >> (i + 1);

                    // add random value
                    value = (ulong)rnd.NextLong(0, tmp) + (ulong)rnd.NextLong(0, tmp);
                    values.Add(value);
                    d.Add(value, bits);
                }
            }

            // add random values for 2-32 bits seperated by 1 bit
            for (int j = 0; j < itemsPerBit; j++)
            {
                d.Add1(false);
                for (int i = 0; i < (maxBits - 2); i++)
                {
                    bits = (byte)(maxBits - i);
                    tmp  = maxVal >> (i + 1);

                    // add random value
                    value = (ulong)rnd.NextLong(0, tmp) + (ulong)rnd.NextLong(0, tmp);
                    values.Add(value);
                    d.Add(value, bits);
                    d.Add1(false);
                }
            }

            BVector d2 = new BVector(d.ToBytes());

            // get values values for 2-32 bits
            for (int j = 0; j < itemsPerBit; j++)
            {
                for (int i = 0; i < (maxBits - 2); i++)
                {
                    bits = (byte)(maxBits - i);

                    // get max
                    expected = values[index];
                    val      = d2.GetULong(bits);
                    Assert.AreEqual(expected, val);
                    index++;
                }
            }

            // get values for 2-32 bits seperated by 1 bit
            for (int j = 0; j < itemsPerBit; j++)
            {
                Assert.AreEqual(false, d2.Get1());
                for (int i = 0; i < (maxBits - 2); i++)
                {
                    bits = (byte)(maxBits - i);

                    // get max
                    expected = values[index];
                    val      = d2.GetULong(bits);
                    Assert.AreEqual(expected, val);
                    Assert.AreEqual(false, d2.Get1());
                    index++;
                }
            }
        }