コード例 #1
0
        public void Double_Rnd()
        {
            BVector       d = new BVector();
            double        value;
            const double  maxValue = double.MaxValue;
            const double  minValue = double.MinValue;
            var           rnd      = new CryptoRandom();
            List <double> values   = new List <double>();

            // number of items to add per bit
            int itemsCount = 1_000;

            for (int i = 0; i < itemsCount; i++)
            {
                // add positive
                value = (double)rnd.NextDouble() * maxValue;
                d.Add(value);
                values.Add(value);
                d.Add1(false);

                // add negative
                value = (double)rnd.NextDouble() * minValue;
                d.Add(value);
                values.Add(value);
                d.Add1(true);
            }

            for (int i = 0; i < itemsCount; i++)
            {
                value = d.GetDouble();
                Assert.AreEqual(values[i], value);
                Assert.AreEqual(i % 2 != 0, d.Get1());
            }
        }
コード例 #2
0
        public void Double_MinMax()
        {
            BVector d    = new BVector();
            double  max  = double.MaxValue;
            double  min  = double.MinValue;
            double  zero = (double)0;

            d.Add(max);
            d.Add1(false);
            d.Add(zero);
            d.Add1(true);
            d.Add(min);

            Assert.AreEqual(max, d.GetDouble());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(zero, d.GetDouble());
            Assert.AreEqual(true, d.Get1());
            Assert.AreEqual(min, d.GetDouble());
        }
コード例 #3
0
ファイル: BHelper.cs プロジェクト: antar4/Antara.Data.Binary
        /// <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);
        }