예제 #1
0
        public void ArithmeticMethods()
        {
            // Abs
            Assert.Equal(6m, SqlDecimal.Abs(_test4));
            Assert.Equal(new SqlDecimal(6464.6464m).Value, SqlDecimal.Abs(_test1).Value);

            Assert.Equal(SqlDecimal.Null, SqlDecimal.Abs(SqlDecimal.Null));

            // Add()
            SqlDecimal test2 = new SqlDecimal(-2000m);

            Assert.Equal(16464.6464m, SqlDecimal.Add(_test1, _test2).Value);
            Assert.Equal("158456325028528675187087900670", SqlDecimal.Add(_test5, _test5).ToString());
            Assert.Equal(9994.00m, SqlDecimal.Add(_test3, _test4));
            Assert.Equal(-2006m, SqlDecimal.Add(_test4, test2));
            Assert.Equal(8000.00m, SqlDecimal.Add(test2, _test3));

            Assert.Throws <OverflowException>(() => SqlDecimal.Add(SqlDecimal.MaxValue, SqlDecimal.MaxValue));

            Assert.Equal(6465m, SqlDecimal.Ceiling(_test1));
            Assert.Equal(SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));

            // Divide
            Assert.Equal(-1077.441066m, SqlDecimal.Divide(_test1, _test4));
            Assert.Equal(1.54687501546m, SqlDecimal.Divide(_test2, _test1).Value, 9);

            Assert.Throws <DivideByZeroException>(() => SqlDecimal.Divide(_test1, new SqlDecimal(0)));

            Assert.Equal(6464m, SqlDecimal.Floor(_test1));

            // Multiply()
            SqlDecimal Test;
            SqlDecimal test1 = new SqlDecimal(2m);

            Assert.Equal(64646464m, SqlDecimal.Multiply(_test1, _test2).Value);
            Assert.Equal(-38787.8784m, SqlDecimal.Multiply(_test1, _test4).Value);
            Test = SqlDecimal.Multiply(_test5, test1);
            Assert.Equal("158456325028528675187087900670", Test.ToString());

            Assert.Throws <OverflowException>(() => SqlDecimal.Multiply(SqlDecimal.MaxValue, _test1));

            // Power
            Assert.Equal(41791653.0770m, SqlDecimal.Power(_test1, 2));

            // Round
            Assert.Equal(6464.65m, SqlDecimal.Round(_test1, 2));

            // Subtract()
            Assert.Equal(-3535.3536m, SqlDecimal.Subtract(_test1, _test3).Value);
            Assert.Equal(10006.00m, SqlDecimal.Subtract(_test3, _test4).Value);
            Assert.Equal("99999999920771837485735662406456049664", SqlDecimal.Subtract(SqlDecimal.MaxValue, decimal.MaxValue).ToString());

            Assert.Throws <OverflowException>(() => SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue));

            Assert.Equal(1, SqlDecimal.Sign(_test1));
            Assert.Equal(new SqlInt32(-1), SqlDecimal.Sign(_test4));
        }
예제 #2
0
        public void ArithmeticMethods()
        {
            // Abs
            Assert.Equal(6m, SqlDecimal.Abs(_test4));
            Assert.Equal(new SqlDecimal(6464.6464m).Value, SqlDecimal.Abs(_test1).Value);

            Assert.Equal(SqlDecimal.Null, SqlDecimal.Abs(SqlDecimal.Null));

            // Add()
            SqlDecimal test2 = new SqlDecimal(-2000m);

            Assert.Equal(16464.6464m, SqlDecimal.Add(_test1, _test2).Value);
            Assert.Equal("158456325028528675187087900670", SqlDecimal.Add(_test5, _test5).ToString());
            Assert.Equal(9994.00m, SqlDecimal.Add(_test3, _test4));
            Assert.Equal(-2006m, SqlDecimal.Add(_test4, test2));
            Assert.Equal(8000.00m, SqlDecimal.Add(test2, _test3));

            try
            {
                SqlDecimal test = SqlDecimal.Add(SqlDecimal.MaxValue, SqlDecimal.MaxValue);
                Assert.False(true);
            }
            catch (OverflowException)
            {
            }

            Assert.Equal(6465m, SqlDecimal.Ceiling(_test1));
            Assert.Equal(SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));

            // Divide() => Notworking

            /*
             *          Assert.Equal ((SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4));
             *          Assert.Equal (1.54687501546m, SqlDecimal.Divide (Test2, Test1).Value);
             *
             *          try {
             *                  SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;
             * Assert.False(true);
             *          } catch (DivideByZeroException e) {
             *                  Assert.Equal (typeof (DivideByZeroException), e.GetType ());
             *          }
             */

            Assert.Equal(6464m, SqlDecimal.Floor(_test1));

            // Multiply()
            SqlDecimal Test;
            SqlDecimal test1 = new SqlDecimal(2m);

            Assert.Equal(64646464.000000m, SqlDecimal.Multiply(_test1, _test2).Value);
            Assert.Equal(-38787.8784m, SqlDecimal.Multiply(_test1, _test4).Value);
            Test = SqlDecimal.Multiply(_test5, test1);
            Assert.Equal("158456325028528675187087900670", Test.ToString());

            try
            {
                SqlDecimal test = SqlDecimal.Multiply(SqlDecimal.MaxValue, _test1);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Power => NotWorking
            //Assert.Equal ((SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2));

            // Round
            Assert.Equal(6464.65m, SqlDecimal.Round(_test1, 2));

            // Subtract()
            Assert.Equal(-3535.3536m, SqlDecimal.Subtract(_test1, _test3).Value);
            Assert.Equal(10006.00m, SqlDecimal.Subtract(_test3, _test4).Value);
            Assert.Equal("99999999920771837485735662406456049664", SqlDecimal.Subtract(SqlDecimal.MaxValue, decimal.MaxValue).ToString());

            try
            {
                SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            Assert.Equal(1, SqlDecimal.Sign(_test1));
            Assert.Equal(new SqlInt32(-1), SqlDecimal.Sign(_test4));
        }
예제 #3
0
        public void ArithmeticMethods()
        {
            // Abs
            Assert.AreEqual((SqlDecimal)6m, SqlDecimal.Abs(Test4), "#D01");
            Assert.AreEqual(new SqlDecimal(6464.6464m).Value, SqlDecimal.Abs(Test1).Value, "#D02");

            Assert.AreEqual(SqlDecimal.Null, SqlDecimal.Abs(SqlDecimal.Null), "#D03");

            // Add()
            SqlDecimal test2 = new SqlDecimal(-2000m);

            Assert.AreEqual(16464.6464m, SqlDecimal.Add(Test1, Test2).Value, "#D04");
            Assert.AreEqual("158456325028528675187087900670", SqlDecimal.Add(Test5, Test5).ToString(), "#D04.1");
            Assert.AreEqual((SqlDecimal)9994.00m, SqlDecimal.Add(Test3, Test4), "#D04.2");
            Assert.AreEqual((SqlDecimal)(-2006m), SqlDecimal.Add(Test4, test2), "#D04.3");
            Assert.AreEqual((SqlDecimal)8000.00m, SqlDecimal.Add(test2, Test3), "#D04.4");

            try {
                SqlDecimal test = SqlDecimal.Add(SqlDecimal.MaxValue, SqlDecimal.MaxValue);
                Assert.Fail("#D05");
            } catch (OverflowException) {
            }

            Assert.AreEqual((SqlDecimal)6465m, SqlDecimal.Ceiling(Test1), "#D07");
            Assert.AreEqual(SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null), "#D08");

            // Divide() => Notworking

            /*
             * Assert.AreEqual ((SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4), "#D09");
             * Assert.AreEqual (1.54687501546m, SqlDecimal.Divide (Test2, Test1).Value, "#D10");
             *
             * try {
             *      SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;
             *      Assert.Fail ("#D11");
             * } catch (DivideByZeroException e) {
             *      Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "#D12");
             * }
             */

            Assert.AreEqual((SqlDecimal)6464m, SqlDecimal.Floor(Test1), "#D13");

            // Multiply()
            SqlDecimal Test;
            SqlDecimal test1 = new SqlDecimal(2m);

            Assert.AreEqual(64646464.000000m, SqlDecimal.Multiply(Test1, Test2).Value, "#D14");
            Assert.AreEqual(-38787.8784m, SqlDecimal.Multiply(Test1, Test4).Value, "#D15");
            Test = SqlDecimal.Multiply(Test5, test1);
            Assert.AreEqual("158456325028528675187087900670", Test.ToString(), "#D15.1");

            try {
                SqlDecimal test = SqlDecimal.Multiply(SqlDecimal.MaxValue, Test1);
                Assert.Fail("#D16");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D17");
            }

            // Power => NotWorking
            //Assert.AreEqual ((SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2), "#D18");

            // Round
            Assert.AreEqual((SqlDecimal)6464.65m, SqlDecimal.Round(Test1, 2), "#D19");

            // Subtract()
            Assert.AreEqual(-3535.3536m, SqlDecimal.Subtract(Test1, Test3).Value, "#D20");
            Assert.AreEqual(10006.00m, SqlDecimal.Subtract(Test3, Test4).Value, "#D20.1");
            Assert.AreEqual("99999999920771837485735662406456049664",
                            SqlDecimal.Subtract(SqlDecimal.MaxValue, Decimal.MaxValue).ToString(),
                            "#D20.2");

            try {
                SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);
                Assert.Fail("#D21");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D22");
            }

            Assert.AreEqual((SqlInt32)1, SqlDecimal.Sign(Test1), "#D23");
            Assert.AreEqual(new SqlInt32(-1), SqlDecimal.Sign(Test4), "#D24");
        }