diff options
author | Paul Phillips <paulp@improving.org> | 2011-09-28 21:52:22 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-09-28 21:52:22 +0000 |
commit | 3a1332c451c8bd9b987ab3dbe775ef5a08360705 (patch) | |
tree | f77b78b14b327cdc18018d0bfaeb28f63cea891f /test/files | |
parent | 82eb1aa430195648b6fe80f67c45c741884dc2d7 (diff) | |
download | scala-3a1332c451c8bd9b987ab3dbe775ef5a08360705.tar.gz scala-3a1332c451c8bd9b987ab3dbe775ef5a08360705.tar.bz2 scala-3a1332c451c8bd9b987ab3dbe775ef5a08360705.zip |
BigDecimal adjustments.
More sensible use of MathContext, plus some BigDecimal tests.
Contributed by Erik Osheim. Closes SI-4981, no review.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/bigDecimalTest.check | 6 | ||||
-rw-r--r-- | test/files/run/bigDecimalTest.scala | 35 |
2 files changed, 41 insertions, 0 deletions
diff --git a/test/files/run/bigDecimalTest.check b/test/files/run/bigDecimalTest.check new file mode 100644 index 0000000000..6d11c23fcd --- /dev/null +++ b/test/files/run/bigDecimalTest.check @@ -0,0 +1,6 @@ +34 +83 +0 +0 +0 +14 diff --git a/test/files/run/bigDecimalTest.scala b/test/files/run/bigDecimalTest.scala new file mode 100644 index 0000000000..480305d7d4 --- /dev/null +++ b/test/files/run/bigDecimalTest.scala @@ -0,0 +1,35 @@ +object Test { + def main(args: Array[String]): Unit = { + + // SI-4981: avoid being limited by math context when not needed + val big = BigDecimal("32432875832753287583275382753288325325328532875325") + val f = big % BigDecimal(scala.math.Pi) + + // SI-1812: use math context to limit decimal expansion + val a = BigDecimal(1) / BigDecimal(3) + val b = BigDecimal(1) / big + + // SI-2199: implicit conversions from java.math.BigDecimal to BigDecimal + val c = BigDecimal(1) + (new java.math.BigDecimal(3)) + + // SI-2024: correctly use BigDecimal.valueOf + assert(BigDecimal(123) + 1.1 == BigDecimal("124.1")) + + // SI-3206: BigDecimal cache errors + val d = BigDecimal(2, new java.math.MathContext(33)) + val e = BigDecimal(2, new java.math.MathContext(34)) + assert(d.mc != e.mc) + + // SI-921 + assert(BigDecimal(2) / BigDecimal(0.5) == BigDecimal(4)) + + // SI-2304: enforce equals/hashCode contract + assert(BigDecimal("2").hashCode == BigDecimal("2.00").hashCode) + + // SI-4547: implicit conversion + assert(5 + BigDecimal(3) == BigDecimal(8)) + + // meaningless sanity check + List[BigDecimal](a, b, c, d, e, f) map (_.scale) foreach println + } +} |