Exemple #1
0
        public void Ext_Short_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short)0, 32);
            d.GetShort(1);
        }
Exemple #2
0
        public void Ext_Short_Get_Exc_MoreThan16Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short)0, 16);
            d.GetShort(17);
        }
Exemple #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);
        }
Exemple #4
0
        public void Ext_Short_AddGet_BitsMinMax_InOut()
        {
            int     maxBits = 16;
            BVector d       = new BVector();
            short   value;
            short   val;
            short   expected;
            short   maxVal = short.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 = (short)(maxVal >> i);
                // add max
                d.Add(value, bits);

                // add min
                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 = (short)(maxVal >> i);
                // add max
                d.Add(value, bits);
                d.Add1(false);

                // add min
                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 = (short)(maxVal >> i);
                val      = d2.GetShort(bits);
                Assert.AreEqual(expected, val);

                // get min
                expected = (short)-expected;
                val      = d2.GetShort(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 = (short)(maxVal >> i);
                val      = d2.GetShort(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());

                // get min
                expected = (short)-expected;
                val      = d2.GetShort(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());
            }
        }
Exemple #5
0
        public void Ext_Short_AddGet_Rnd_InOut()
        {
            BVector      d           = new BVector();
            var          rnd         = new CryptoRandom();
            List <short> values      = new List <short>();
            int          maxBits     = 16;
            int          index       = 0;
            int          itemsPerBit = 100;
            short        value;
            short        val;
            short        expected;
            short        maxVal = short.MaxValue;
            short        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  = (short)(maxVal >> (i + 1));

                    // add random value
                    value = (short)rnd.Next(-tmp, 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  = (short)(maxVal >> (i + 1));

                    // add random value
                    value = (short)rnd.NextLong(-tmp, 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.GetShort(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.GetShort(bits);
                    Assert.AreEqual(expected, val);
                    Assert.AreEqual(false, d2.Get1());
                    index++;
                }
            }
        }