From b8a4a97a6bb6c2946fa51e630551747b03874d1a Mon Sep 17 00:00:00 2001 From: Zhong Sheng Date: Fri, 29 May 2015 06:28:22 +0800 Subject: add more test for testMathContext --- test/junit/scala/math/BigDecimalTest.scala | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/junit/scala/math/BigDecimalTest.scala b/test/junit/scala/math/BigDecimalTest.scala index dedf2e242e..a801204cb2 100644 --- a/test/junit/scala/math/BigDecimalTest.scala +++ b/test/junit/scala/math/BigDecimalTest.scala @@ -232,7 +232,31 @@ class BigDecimalTest { // Motivated by the problem of MathContext lost @Test def testMathContext() { - assert(BigDecimal(1.1d, MC.UNLIMITED).pow(1000) == BigDecimal("1.1", MC.UNLIMITED).pow(1000)) - assert((BigDecimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) + def testPrecision() { + val e = 1000 + + val n = BigDecimal("1.1", MC.UNLIMITED).pow(e) + assert(BigDecimal(1.1d, MC.UNLIMITED).pow(e) == n) + assert(BigDecimal.decimal(1.1d, MC.UNLIMITED).pow(e) == n) + assert(BigDecimal.decimal(1.1f, MC.UNLIMITED).pow(e) == n) + assert(BigDecimal.decimal(new BD("1.1"), MC.UNLIMITED).pow(e) == n) + + val m = BigDecimal(java.lang.Double.toString(1.1f.toDouble), MC.UNLIMITED).pow(e) + assert(BigDecimal(1.1f, MC.UNLIMITED).pow(e) == m) // deprecated + + val l = BigDecimal("11", MC.UNLIMITED).pow(e) + assert(BigDecimal(11, MC.UNLIMITED).pow(e) == l) + assert(BigDecimal.decimal(11, MC.UNLIMITED).pow(e) == l) + } + + def testRounded() { + assert((BigDecimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) + assert((BigDecimal(1.23f, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) // deprecated + assert((BigDecimal.decimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) + assert((BigDecimal.decimal(1.23f, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) + } + + testPrecision() + testRounded() } } -- cgit v1.2.3