public void DoubleN_MinMax()
        {
            BVector d     = new BVector();
            double? max   = double.MaxValue;
            double? min   = double.MinValue;
            double? zero  = (double)0;
            double? @null = null;


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

            Assert.AreEqual(max, d.GetDoubleN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(@null, d.GetDoubleN());
            Assert.AreEqual(true, d.Get1());
            Assert.AreEqual(zero, d.GetDoubleN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(min, d.GetDoubleN());
        }
Beispiel #2
0
        public void DecimalN_MinMax()
        {
            BVector  d     = new BVector();
            decimal? max   = decimal.MaxValue;
            decimal? min   = decimal.MinValue;
            decimal? zero  = (decimal)0;
            decimal? @null = null;


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

            Assert.AreEqual(max, d.GetDecimalN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(@null, d.GetDecimalN());
            Assert.AreEqual(true, d.Get1());
            Assert.AreEqual(zero, d.GetDecimalN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(min, d.GetDecimalN());
        }
Beispiel #3
0
        public void Decimal_Rnd()
        {
            BVector        d = new BVector();
            decimal        value;
            const decimal  maxValue = decimal.MaxValue;
            const decimal  minValue = decimal.MinValue;
            var            rnd      = new CryptoRandom();
            List <decimal> values   = new List <decimal>();

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

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

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

            for (int i = 0; i < itemsCount; i++)
            {
                value = d.GetDecimal();
                Assert.AreEqual(values[i], value);
                Assert.AreEqual(i % 2 != 0, d.Get1());
            }
        }
        public void Int_AddGet_BitsMinMax_Separated_Loopback()
        {
            int maxBits = 32;
            List<int> values = new List<int>();
            BVector d = new BVector();
            int positiveValue;
            int negativeValue;
            int actualValue;
            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);

                // true separator
                d.Add1();

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

                // false separator
                d.Add1(false);
            }


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

                // true separator
                Assert.AreEqual(true, d.Get1());

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

                // false separator
                Assert.AreEqual(false, d.Get1());
            }
        }
        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);
            }
        }
Beispiel #6
0
        public void Ext_ULong_AddGet_BitsMinMax_InOut()
        {
            int     maxBits = 64;
            BVector d       = new BVector();
            ulong   value;
            ulong   val;
            ulong   expected;
            ulong   maxVal = ulong.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 = maxVal >> i;
                // add max
                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 = maxVal >> i;
                // add max
                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 = maxVal >> i;
                val      = d2.GetULong(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 = maxVal >> i;
                val      = d2.GetULong(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());
            }
        }
        public void Ext_UInt_AddGet_BitsMax_InOut()
        {
            BVector d = new BVector();
            uint    value;
            uint    val;
            uint    expected;
            uint    maxVal = uint.MaxValue;
            byte    bits;


            // add max values for 2-32 bits
            for (int i = 0; i < 31; i++)
            {
                bits  = (byte)(32 - i);
                value = maxVal >> i;
                // add max
                d.Add(value, bits);
            }

            // add max values for 2-32 bits seperated by 1 bit
            d.Add1(false);
            for (int i = 0; i < 31; i++)
            {
                bits  = (byte)(32 - i);
                value = maxVal >> i;
                // add max
                d.Add(value, bits);
                d.Add1(false);
            }

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

            // get max values for 2-32 bits
            for (int i = 0; i < 31; i++)
            {
                bits = (byte)(32 - i);

                // get max
                expected = maxVal >> i;
                val      = d2.GetUInt(bits);
                Assert.AreEqual(expected, val);
            }

            // get max values for 2-32 bits seperated by 1 bit
            Assert.AreEqual(false, d2.Get1());
            for (int i = 0; i < 31; i++)
            {
                bits = (byte)(32 - i);

                // get max
                expected = maxVal >> i;
                val      = d2.GetUInt(bits);
                Assert.AreEqual(expected, val);
                Assert.AreEqual(false, d2.Get1());
            }
        }
Beispiel #8
0
        public void DateTime_MinMax()
        {
            DateTime max = DateTime.MaxValue;
            DateTime min = DateTime.MinValue;
            BVector  d   = new BVector();

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

            Assert.AreEqual(max, d.GetDateTime());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(min, d.GetDateTime());
        }
Beispiel #9
0
        public void TimeSpan_MinMax()
        {
            TimeSpan max = TimeSpan.MaxValue;
            TimeSpan min = TimeSpan.MinValue;
            BVector  d   = new BVector();

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

            Assert.AreEqual(max, d.GetTimeSpan());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(min, d.GetTimeSpan());
        }
Beispiel #10
0
        public void DateTimeN_Current()
        {
            DateTime? dt    = DateTime.Now;
            DateTime? @null = null;
            BVector   d     = new BVector();

            d.Add(@null);
            d.Add1(false);
            d.Add(dt);


            Assert.AreEqual(@null, d.GetDateTimeN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(dt, d.GetDateTimeN());
        }
        public void Long_AddGet_BitsMinMax_Sequence_Loopback()
        {
            int         maxBits = 64;
            List <long> values  = new List <long>();
            BVector     d       = new BVector();
            long        positiveValue;
            long        negativeValue;
            long        actualValue;
            int         index;
            long        expected;
            long        maxVal = long.MaxValue;
            byte        bits;


            // add min and max values for 2-64 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 negative
                d.Add(negativeValue, bits);
                values.Add(negativeValue);
            }


            // get min and max values for 2-64 bits
            index = 0;
            for (int i = 0; i < (maxBits - 1); i++)
            {
                bits = (byte)(maxBits - i);

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

                // get min
                expected    = values[index++];
                actualValue = d.GetLong(bits);
                Assert.AreEqual(expected, actualValue);
            }
        }
        public void Ext_UIntN_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((uint?)0, 32);
            d.GetUIntN(1);
        }
Beispiel #13
0
        public void Ext_Short_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short)0, 32);
            d.GetShort(1);
        }
        public void Long_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add(0, 32);
            d.GetLong(1);
        }
Beispiel #15
0
        public void Ext_ShortN_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short?)0, 16);
            d.GetShortN(1);
        }
Beispiel #16
0
        public void Ext_ShortN_Get_Exc_MoreThan16Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((short?)0, 16);
            d.GetShortN(17);
        }
        public void Ext_UIntN_Get_Exc_MoreThan32Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((uint?)0, 32);
            d.GetUIntN(33);
        }
Beispiel #18
0
        public void Ext_ULongN_Get_Exc_MoreThan32Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((ulong?)0, 32);
            d.GetULongN(65);
        }
        public void LongN_Get_Exc_MoreThan64Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((long?)0, 32);
            d.GetLongN(65);
        }
Beispiel #20
0
        public void Ext_ULongN_Get_Exc_LessThan2Bits_Loopback()
        {
            BVector d = new BVector();

            d.Add((ulong?)0, 32);
            d.GetULongN(1);
        }
Beispiel #21
0
        public void TimeSpan_Basic()
        {
            TimeSpan ts = new TimeSpan(DateTime.Now.Ticks);
            BVector  d  = new BVector();

            d.Add(ts);

            Assert.AreEqual(ts, d.GetTimeSpan());
        }
Beispiel #22
0
        public void DateTime_Current()
        {
            DateTime dt = DateTime.Now;
            BVector  d  = new BVector();

            d.Add(dt);

            Assert.AreEqual(dt, d.GetDateTime());
        }
Beispiel #23
0
        public void DateTimeN_MinMax()
        {
            DateTime? max   = DateTime.MaxValue;
            DateTime? min   = DateTime.MinValue;
            DateTime? @null = null;
            BVector   d     = new BVector();

            d.Add(max);
            d.Add1(false);
            d.Add(@null);
            d.Add1(false);
            d.Add(min);

            Assert.AreEqual(max, d.GetDateTimeN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(@null, d.GetDateTimeN());
            Assert.AreEqual(false, d.Get1());
            Assert.AreEqual(min, d.GetDateTimeN());
        }
        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());
        }
Beispiel #25
0
        public void String_Unicode()
        {
            string  unicodeChars = BHelper.GetUnicodeCharacters();
            BVector d            = new BVector();

            d.Add(unicodeChars);
            string stored = d.GetString();

            Assert.AreEqual(unicodeChars, stored);
        }
        public void ByteArray_Basic()
        {
            var     rnd        = new CryptoRandom();
            int     itemsCount = 1_000;
            BVector d          = new BVector();

            byte[] values = rnd.NextBytes(itemsCount);

            d.Add(values);
            Assert.IsTrue(BHelper.CompareByteArrays(values, d.GetByteArray()));
        }
Beispiel #27
0
        public void String_Basic256()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 256; i++)
            {
                sb.Append((char)i);
            }
            string  s = sb.ToString();
            BVector d = new BVector();

            d.Add(s);
            Assert.AreEqual(s, d.GetString());
        }
        public void Long_AddGet_Rnd_Sequence_Loopback()
        {
            int         maxBits = 64;
            List <long> values  = new List <long>();
            BVector     d       = new BVector();
            long        actualValue;
            int         index;
            long        expected;
            long        maxVal = long.MaxValue;
            byte        bits;
            var         rnd         = new CryptoRandom();
            int         itemsPerBit = 10000;
            long        value;
            long        tmp;


            // add random values for 2-64 bits
            for (int j = 0; j < itemsPerBit; j++)
            {
                for (int i = 0; i < (maxBits - 2); i++)
                {
                    bits = (byte)(maxBits - i);
                    tmp  = maxVal >> (i + 1);

                    // add random value
                    value = rnd.NextLong(-tmp - 1, tmp);
                    values.Add(value);
                    d.Add(value, bits);
                }
            }

            // get values for 2-64 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.GetLong(bits);
                    Assert.AreEqual(expected, actualValue);
                    index++;
                }
            }
        }
        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++;
                }
            }
        }
        public void Ext_UInt_AddGet_Rnd_InOut()
        {
            int         maxBits = 32;
            int         index   = 0;
            byte        bits;
            uint        value;
            uint        expected;
            const uint  maxValue = uint.MaxValue;
            uint        rngMax;
            var         rnd    = new CryptoRandom();
            List <uint> values = new List <uint>();

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

            for (int j = 2; j <= maxBits; j++)
            {
                rngMax = maxValue >> (maxBits - j);
                bits   = (byte)j;
                for (int i = 0; i < itemsCount; i++)
                {
                    // add positive
                    value = (uint)rnd.NextLong(rngMax);
                    d.Add(value, bits);
                    values.Add(value);
                    d.Add1(false);
                }
            }

            BVector d2 = d;

            for (int j = 2; j < maxBits; j++)
            {
                bits = (byte)j;
                for (int i = 0; i < itemsCount; i++)
                {
                    // read positive
                    value    = d2.GetUInt(bits);
                    expected = values[index];
                    Assert.AreEqual(expected, value);
                    Assert.AreEqual(false, d2.Get1());
                    index++;
                }
            }
        }