Exemplo n.º 1
0
        public void Int_AddGet_BitsMinMax_Separated_Loopback()
        {
            int maxBits = 32;
            List<int> values = new List<int>();
            BVector d = new BVector();
            int positiveValue;
            int negativeValue;
            int actualValue;
            int index;
            int expected;
            int maxVal = int.MaxValue;
            byte bits;


            // add min and max values for 2-32 bits
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits = (byte)(maxBits - i);
                positiveValue = maxVal >> i;
                negativeValue = -positiveValue - 1;

                // add positive
                d.Add(positiveValue, bits);
                values.Add(positiveValue);

                // true separator
                d.Add1();

                // add negative
                d.Add(negativeValue, bits);
                values.Add(negativeValue);

                // false separator
                d.Add1(false);
            }


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

                // get positive
                expected = values[index++];
                actualValue = d.GetInt(bits);
                Assert.AreEqual(expected, actualValue);

                // true separator
                Assert.AreEqual(true, d.Get1());

                // get min
                expected = values[index++];
                actualValue = d.GetInt(bits);
                Assert.AreEqual(expected, actualValue);

                // false separator
                Assert.AreEqual(false, d.Get1());
            }
        }
Exemplo n.º 2
0
        public void Int_AddGet_Rnd_Sequence_Loopback()
        {
            int maxBits = 32;
            List<int> values = new List<int>();
            BVector d = new BVector();
            int actualValue;
            int index;
            int expected;
            int maxVal = int.MaxValue;
            byte bits;
            var rnd = new CryptoRandom();
            int itemsPerBit = 10000;
            int value;
            int tmp;


            // 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 = rnd.Next(-tmp - 1, tmp);
                    values.Add(value);
                    d.Add(value, bits);
                }
            }

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

                    // get value
                    expected = values[index];
                    actualValue = d.GetInt(bits);
                    Assert.AreEqual(expected, actualValue);
                    index++;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the next random value added by <see cref="WriteRandomValue(BVector)"/>
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static object ReadNextRandomValue(BVector d)
        {
            bool nullable  = d.Get1();
            byte valueType = d.Get8();

            switch (valueType)
            {
            case 0:
                if (nullable)
                {
                    return(d.GetIntN());
                }
                return(d.GetInt());

            case 1:
                if (nullable)
                {
                    return(d.GetLongN());
                }
                return(d.GetLong());

            case 2:
                if (nullable)
                {
                    return(d.GetShortN());
                }
                return(d.GetShort());

            case 3:
                if (nullable)
                {
                    return(d.GetByteN());
                }
                return(d.GetByte());

            case 4:
                return(d.GetString());

            case 5:
                return(d.GetAscii());

            case 6:
                if (nullable)
                {
                    return(d.GetDateTimeN());
                }
                return(d.GetDateTime());

            case 7:
                if (nullable)
                {
                    return(d.GetDecimalN());
                }
                return(d.GetDecimal());

            case 8:
                if (nullable)
                {
                    return(d.GetDoubleN());
                }
                return(d.GetDouble());

            case 9:
                return(d.Get1());

            case 10:
                return(d.GetTimeSpan());

            case 11:
                return(d.GetByteArray());
            }
            return(null);
        }
Exemplo n.º 4
0
 public void Int_Get_Exc_MoreThan32Bits_Loopback()
 {
     BVector d = new BVector();
     d.Add(0, 32);
     d.GetInt(33);
 }
Exemplo n.º 5
0
 public void Int_Get_Exc_LessThan2Bits_Loopback()
 {
     BVector d = new BVector();
     d.Add(0, 32);
     d.GetInt(1);
 }