public void Basic_8_AddGet_Safe_Random_InOut()
        {
            int         index    = 0;
            byte        maxValue = byte.MaxValue;
            byte        value;
            byte        expected;
            var         rnd    = new CryptoRandom();
            List <byte> values = new List <byte>();

            // number of items to add per bit
            int     itemsCount = 1_000;
            BVector d          = new BVector();

            for (int i = 0; i < itemsCount; i++)
            {
                value = (byte)rnd.NextLong(maxValue);
                d.Add8(value);
                values.Add(value);
                // add 1 bit to split bytes
                d.Add1(false);
            }

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

            for (int i = 0; i < itemsCount; i++)
            {
                value    = d2.Get8();
                expected = values[index];
                Assert.AreEqual(expected, value);
                Assert.AreEqual(false, d2.Get1());
                index++;
            }
        }
Exemple #2
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);
        }