Пример #1
0
        public void NpgsqlMpAdd()
        {
            var num = new NpgsqlDecimal(1000000m);

            num.MpAdd(20);

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(new uint[] { 1000020 }));
        }
Пример #2
0
        public void NpgsqlMpMultiply()
        {
            var num = new NpgsqlDecimal(10000000000000000000000000m);

            num.MpMultiply(20);

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(new uint[] { 3355443200, 3113228709, 10842021 }));
        }
Пример #3
0
        public void NpgsqlDoubleImplicitConversion()
        {
            var num = (NpgsqlDecimal)(3000000001.000003400001d);

            var bits = new uint[] { 1339791009, 6984919 };

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(bits));
            Assert.That(num.Positive);
        }
Пример #4
0
        public void NpgsqlLongImplicitConversion()
        {
            var num = (NpgsqlDecimal)((long)10000000000);

            var bits = new uint[] { 1410065408, 2 };

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Positive);
        }
Пример #5
0
        public void NpgsqlDecimalSubstractOperator()
        {
            var result = new NpgsqlDecimal(99999999999999999999999.99999m)
                         -
                         new NpgsqlDecimal(11111111111111111111111.11111m);

            Assert.That(NpgsqlDecimal.GetBits(result), Is.EqualTo(new uint[] { 3101920824, 926766962, 481867632 }));
            Assert.That(result.Scale == 5);
            Assert.That(result.Positive);
        }
Пример #6
0
        public async Task WriteNgpsqlDecimal(string query, decimal expected)
        {
            using var conn = await OpenConnectionAsync();

            using var cmd = new NpgsqlCommand("SELECT @p, @p = " + query, conn);
            cmd.Parameters.AddWithValue("p", expected);
            using var rdr = await cmd.ExecuteReaderAsync();

            rdr.Read();
            Assert.That(NpgsqlDecimal.GetBits(rdr.GetFieldValue <NpgsqlDecimal>(0)), Is.EqualTo(NpgsqlDecimal.GetBits((NpgsqlDecimal)expected)));
            Assert.That(rdr.GetFieldValue <bool>(1));
        }
Пример #7
0
        public void NpgsqlMultiplyOperator()
        {
            var operand1 = new NpgsqlDecimal(300000000000001.000486734785m);
            var operand2 = new NpgsqlDecimal(2000.129384789237489237489237m);
            var result   = operand1 * operand2;
            //result should be 600038815436773247.874164106415061017127186137711009045

            var bits = new uint[] {
                2271370517, 2936620743, 2582976012, 1689395818, 936602412, 410563
            };

            Assert.That(result.Scale == 36);
            Assert.That(result.Positive);
            Assert.That(NpgsqlDecimal.GetBits(result), Is.EqualTo(bits));
        }
Пример #8
0
        public void NpgsqlDivideOperator()
        {
            var operand1 = new NpgsqlDecimal(1000000000000000000000000000m);
            var operand2 = new NpgsqlDecimal(2m);
            var result   = operand1 / operand2;

            Assert.That(NpgsqlDecimal.GetBits(result), Is.EqualTo(new uint[] { 0, 2623581573, 3810674377, 6310 }));
            Assert.That(result.Positive);
            Assert.That(result.Scale == 6);

            operand1 = new NpgsqlDecimal(1000000000000000000000000000m);
            operand2 = new NpgsqlDecimal(200000000000000000000000000m);
            result   = operand1 / operand2;
            Assert.That(NpgsqlDecimal.GetBits(result), Is.EqualTo(new uint[] { 1342177280, 918096869, 2710505431 }));
            Assert.That(result.Scale == 28);
        }
Пример #9
0
        public void NpgsqlDecimalIntConstructor()
        {
            //Max Value
            var num  = new NpgsqlDecimal(int.MaxValue);
            var bits = new uint[] { 2147483647 };

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Positive);

            //Min value
            num  = new NpgsqlDecimal(int.MinValue);
            bits = new uint[] { 2147483648 };

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Negative);
        }
Пример #10
0
        public void NpgsqlDecimalDoubleConstructor()
        {
            //Max value
            var num     = new NpgsqlDecimal(double.MaxValue);
            var numBits = NpgsqlDecimal.GetBits(num);
            var bits    = new uint[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 107126352, 4087786100, 866356121, 2275956310, 3174582669, 3640009423, 1013472480, 256755600, 656218509, 4246097956, 2450687296, 1359996789, 3916874882, 2924277660, 3106322741, 3546470216, 3649033932, 4189631022, 1434106335, 3039171059, 1797681499, 4294965164, 4294967295 };

            Assert.That(numBits.Length == 32);
            Assert.That(numBits, Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Positive);

            //Min value
            num     = new NpgsqlDecimal(double.MinValue);
            numBits = NpgsqlDecimal.GetBits(num);

            Assert.That(numBits.Length == 32);
            Assert.That(numBits, Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Negative);
        }
Пример #11
0
        public void NpgsqlDecimalCopyConstructor()
        {
            //positive value
            var num1     = new NpgsqlDecimal(123456789123456789.123456789123456789);
            var num1Bits = NpgsqlDecimal.GetBits(num1);
            var num2     = new NpgsqlDecimal(num1);
            var num2Bits = NpgsqlDecimal.GetBits(num2);

            Assert.That(num1Bits, Is.EqualTo(num2Bits));
            Assert.That(num1.Scale == num2.Scale);
            Assert.That(num1.Positive == num2.Positive);

            //negative value
            num1     = new NpgsqlDecimal(-123456789123456789.123456789123456789);
            num1Bits = NpgsqlDecimal.GetBits(num1);
            num2     = new NpgsqlDecimal(num1);
            num2Bits = NpgsqlDecimal.GetBits(num2);

            Assert.That(num1Bits, Is.EqualTo(num2Bits));
            Assert.That(num1.Scale == num2.Scale);
            Assert.That(num1.Positive == num2.Positive);
        }
Пример #12
0
        public void NpgsqlDecimalDecimalConstructor()
        {
            var num     = new NpgsqlDecimal(decimal.MaxValue);
            var numBits = NpgsqlDecimal.GetBits(num);

            var bits = new uint[] { 4294967295, 4294967295, 4294967295 };

            Assert.That(numBits.Length == 3);
            Assert.That(numBits, Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Positive);

            num     = new NpgsqlDecimal(decimal.MinValue);
            numBits = NpgsqlDecimal.GetBits(num);

            bits = new uint[] { 4294967295, 4294967295, 4294967295 };

            Assert.That(numBits.Length == 3);
            Assert.That(numBits, Is.EqualTo(bits));
            Assert.That(num.Scale == 0);
            Assert.That(num.Negative);
        }
Пример #13
0
        public void NpgsqlSumOperatorHighPrecision()
        {
            var operand1 = NpgsqlDecimal.Parse("530924859032485093248509283459083249058230495890285092384590834095832094582340985203948590234850923845239048520934850932485092384509832405823405890485902348502384509238459028340958234905823094850923485093248590823405982340958.001");
            var operand2 = NpgsqlDecimal.Parse("600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000010000000000.001");
            var result   = operand1 + operand2;
            var bits     = new uint[] {
                1648879410
                , 3326410772
                , 3841557637
                , 2791007439
                , 1521403836
                , 2021754616
                , 3645313116
                , 2511060613
                , 3477521390
                , 3810089742
                , 3797290586
                , 3215693652
                , 3109225219
                , 284600426
                , 3563169865
                , 963530200
                , 2802493748
                , 3232850576
                , 1749935321
                , 418262482
                , 3234429662
                , 1948742115
                , 3061963145
                , 3128649
            };

            Assert.That(NpgsqlDecimal.GetBits(result), Is.EqualTo(bits));
            Assert.That(result.Scale == 3);
            Assert.That(result.Positive);
        }
Пример #14
0
        public void NpgsqlDecimalParseString()
        {
            var num = NpgsqlDecimal.Parse("200000000000000000000000000");

            Assert.That(NpgsqlDecimal.GetBits(num), Is.EqualTo(new uint[] { 3355443200, 3113228709, 10842021 }));
        }