Пример #1
0
        public void IntN_AddGet_BitsMinMax_Sequence_Loopback()
        {
            int maxBits = 32;
            List<int?> values = new List<int?>();
            BVector d = new BVector();
            int? positiveValue;
            int? negativeValue;
            int? actualValue;
            int? nullValue = null;
            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);

                // add null
                d.Add(nullValue, bits);
                values.Add(nullValue);

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


            // 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.GetIntN(bits);
                Assert.AreEqual(expected, actualValue);

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

                // get negative
                expected = values[index++];
                actualValue = d.GetIntN(bits);
                Assert.AreEqual(expected, actualValue);
            }
        }
Пример #2
0
        public void IntN_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.Value >> (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.GetIntN(bits);
                    Assert.AreEqual(expected, actualValue);
                    index++;
                }
            }
        }
Пример #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);
        }
Пример #4
0
 public void IntN_Get_Exc_MoreThan32Bits_Loopback()
 {
     BVector d = new BVector();
     d.Add((int?)0, 32);
     d.GetIntN(33);
 }
Пример #5
0
 public void IntN_Get_Exc_LessThan2Bits_Loopback()
 {
     BVector d = new BVector();
     d.Add((int?)0, 32);
     d.GetIntN(1);
 }