summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhong Sheng <shengzhong@sohu-inc.com>2015-06-18 10:43:18 +0800
committerZhong Sheng <shengzhong@sohu-inc.com>2015-06-18 10:43:18 +0800
commit5ab401084141d37c03dc29c9028917b92e56ca68 (patch)
tree12e888c80aae0b8f28e7d5b4b12533d0991ceaff
parentb8a4a97a6bb6c2946fa51e630551747b03874d1a (diff)
downloadscala-5ab401084141d37c03dc29c9028917b92e56ca68.tar.gz
scala-5ab401084141d37c03dc29c9028917b92e56ca68.tar.bz2
scala-5ab401084141d37c03dc29c9028917b92e56ca68.zip
make BigDecimalTest.testMathContext a bit easier to understand
-rw-r--r--test/junit/scala/math/BigDecimalTest.scala27
1 files changed, 14 insertions, 13 deletions
diff --git a/test/junit/scala/math/BigDecimalTest.scala b/test/junit/scala/math/BigDecimalTest.scala
index a801204cb2..a9e2481f37 100644
--- a/test/junit/scala/math/BigDecimalTest.scala
+++ b/test/junit/scala/math/BigDecimalTest.scala
@@ -233,27 +233,28 @@ class BigDecimalTest {
@Test
def testMathContext() {
def testPrecision() {
- val e = 1000
+ val p = 1000
+ val n = BigDecimal("1.1", MC.UNLIMITED).pow(p)
- 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)
+ // BigDecimal(x: Float, mc: MC), which may not do what you want, is deprecated
+ assert(BigDecimal(1.1f, MC.UNLIMITED).pow(p) == BigDecimal(java.lang.Double.toString(1.1f.toDouble), MC.UNLIMITED).pow(p))
+ assert(BigDecimal(1.1d, MC.UNLIMITED).pow(p) == n)
+ assert(BigDecimal(new BD("1.1"), MC.UNLIMITED).pow(p) == 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
+ assert(BigDecimal.decimal(1.1f, MC.UNLIMITED).pow(p) == n)
+ assert(BigDecimal.decimal(1.1d, MC.UNLIMITED).pow(p) == n)
+ assert(BigDecimal.decimal(new BD("1.1"), MC.UNLIMITED).pow(p) == n)
- 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)
+ assert((BigDecimal(11, MC.UNLIMITED) / 10).pow(p) == n)
+ assert((BigDecimal.decimal(11, MC.UNLIMITED) / 10).pow(p) == n)
}
def testRounded() {
+ // the default rounding mode is HALF_UP
+ assert((BigDecimal(1.23f, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) // deprecated api
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"))
+ assert((BigDecimal.decimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24"))
}
testPrecision()