Ejemplo n.º 1
0
        public void Ext_ShortN_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short?)0, 16);
            d.GetShortN(1);
        }
Ejemplo n.º 2
0
        public void Ext_ShortN_Get_Exc_MoreThan16Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short?)0, 16);
            d.GetShortN(17);
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public void Ext_ShortN_AddGet_BitsMinMax_InOut()
        {
            int         maxBits = 16;
            BVector     d       = new BVector();
            short?      value;
            short?      val;
            short?      expected;
            short?      nullVal = (short?)null;
            const 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 null
                d.Add(nullVal, 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);

                // add null
                d.Add(nullVal, 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.GetShortN(bits);
                Assert.AreEqual(expected, val);

                // get min
                expected = (short)-expected;
                val      = d2.GetShortN(bits);
                Assert.AreEqual(expected, val);

                // get null
                expected = nullVal;
                val      = d2.GetShortN(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.GetShortN(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());

                // get min
                expected = (short)-expected;
                val      = d2.GetShortN(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());

                // get null
                expected = nullVal;
                val      = d2.GetShortN(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());
            }
        }