summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorZhong Sheng <nicky_zs@163.com>2015-05-29 06:28:22 +0800
committerZhong Sheng <nicky_zs@163.com>2015-05-29 06:28:22 +0800
commitb8a4a97a6bb6c2946fa51e630551747b03874d1a (patch)
tree38b948c68e19b697fb8d802fd2631239a4d7efd2 /test
parent31d08571bb19bb7b16197476a1c2f7dc319e3ba2 (diff)
downloadscala-b8a4a97a6bb6c2946fa51e630551747b03874d1a.tar.gz
scala-b8a4a97a6bb6c2946fa51e630551747b03874d1a.tar.bz2
scala-b8a4a97a6bb6c2946fa51e630551747b03874d1a.zip
add more test for testMathContext
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/math/BigDecimalTest.scala28
1 files 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()
}
}