Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit b8a4a97

Browse files
committed
add more test for testMathContext
1 parent 31d0857 commit b8a4a97

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/junit/scala/math/BigDecimalTest.scala

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,31 @@ class BigDecimalTest {
232232
// Motivated by the problem of MathContext lost
233233
@Test
234234
def testMathContext() {
235-
assert(BigDecimal(1.1d, MC.UNLIMITED).pow(1000) == BigDecimal("1.1", MC.UNLIMITED).pow(1000))
236-
assert((BigDecimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24"))
235+
def testPrecision() {
236+
val e = 1000
237+
238+
val n = BigDecimal("1.1", MC.UNLIMITED).pow(e)
239+
assert(BigDecimal(1.1d, MC.UNLIMITED).pow(e) == n)
240+
assert(BigDecimal.decimal(1.1d, MC.UNLIMITED).pow(e) == n)
241+
assert(BigDecimal.decimal(1.1f, MC.UNLIMITED).pow(e) == n)
242+
assert(BigDecimal.decimal(new BD("1.1"), MC.UNLIMITED).pow(e) == n)
243+
244+
val m = BigDecimal(java.lang.Double.toString(1.1f.toDouble), MC.UNLIMITED).pow(e)
245+
assert(BigDecimal(1.1f, MC.UNLIMITED).pow(e) == m) // deprecated
246+
247+
val l = BigDecimal("11", MC.UNLIMITED).pow(e)
248+
assert(BigDecimal(11, MC.UNLIMITED).pow(e) == l)
249+
assert(BigDecimal.decimal(11, MC.UNLIMITED).pow(e) == l)
250+
}
251+
252+
def testRounded() {
253+
assert((BigDecimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24"))
254+
assert((BigDecimal(1.23f, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24")) // deprecated
255+
assert((BigDecimal.decimal(1.23d, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24"))
256+
assert((BigDecimal.decimal(1.23f, new MC(3)) + BigDecimal("0.005")).rounded == BigDecimal("1.24"))
257+
}
258+
259+
testPrecision()
260+
testRounded()
237261
}
238262
}

0 commit comments

Comments
 (0)