diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-15 14:13:53 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-15 14:13:53 -0800 |
commit | 4f7ff0ad530fee6d75c95194ecec87a8c1ce4486 (patch) | |
tree | 8296f1d33ddb46c61102c40d3ee12a81540f5c4a /test/files/run/numbereq.scala | |
parent | 6ea9933e262ab286165511a90f3e1df341e032a4 (diff) | |
parent | 29541ce3961a797836b232ccc12a60cc09f5de3e (diff) | |
download | scala-4f7ff0ad530fee6d75c95194ecec87a8c1ce4486.tar.gz scala-4f7ff0ad530fee6d75c95194ecec87a8c1ce4486.tar.bz2 scala-4f7ff0ad530fee6d75c95194ecec87a8c1ce4486.zip |
Merge pull request #3316 from Ichoran/topic/big-decimal-correctness
Quasi-comprehensive BigDecimal soundness/correctness fix.
Diffstat (limited to 'test/files/run/numbereq.scala')
-rw-r--r-- | test/files/run/numbereq.scala | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/test/files/run/numbereq.scala b/test/files/run/numbereq.scala index d50db6d049..7ce4b23cf8 100644 --- a/test/files/run/numbereq.scala +++ b/test/files/run/numbereq.scala @@ -31,6 +31,24 @@ object Test { ).flatten } + // Don't necessarily expect BigDecimal created from BigInt to agree with Double here. + def isIffy(x: Any, y: Any, canSwap: Boolean = true): Boolean = x match { + case bd: BigDecimal => y match { + case _: Float | _: Double => bd.toString.length > 15 + case _ => false + } + case _ => canSwap && isIffy(y, x, false) + } + + // Don't necessarily expect BigInt to agree with Float/Double beyond a Long + def isIffyB(x: Any, y: Any, canSwap: Boolean = true): Boolean = x match { + case bi: BigInt => y match { + case _: Float | _: Double => bi < Long.MinValue || bi > Long.MaxValue + case _ => false + } + case _ => canSwap && isIffyB(y, x, false) + } + def main(args: Array[String]): Unit = { val ints = (0 to 15).toList map (Short.MinValue >> _) val ints2 = ints map (x => -x) @@ -46,7 +64,6 @@ object Test { val sets = setneg1 ++ setneg2 ++ List(zero) ++ setpos1 ++ setpos2 for (set <- sets ; x <- set ; y <- set) { - // println("'%s' == '%s' (%s == %s) (%s == %s)".format(x, y, x.hashCode, y.hashCode, x.##, y.##)) assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) assert(x.## == y.##, "%s != %s".format(x.getClass, y.getClass)) } @@ -64,9 +81,11 @@ object Test { val sets2 = setneg1 ++ setneg1b ++ setneg2 ++ setneg2b ++ List(zero) ++ setpos1 ++ setpos1b ++ setpos2 ++ setpos2b for (set <- sets2 ; x <- set ; y <- set) { -// println("'%s' == '%s' (%s == %s) (%s == %s)".format(x, y, x.hashCode, y.hashCode, x.##, y.##)) - assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) -// assert(x.## == y.##, "%s != %s".format(x.getClass, y.getClass)) Disable until Double.## is fixed (SI-5640) + if (!isIffy(x,y)) { + assert(x == y, "%s/%s != %s/%s".format(x, x.getClass, y, y.getClass)) + // The following is blocked by SI-8150 + // if (!isIffyB(x,y)) assert(x.## == y.##, "%x/%s != %x/%s from %s.## and %s.##".format(x.##, x.getClass, y.##, y.getClass, x, y)) + } } } } |