From 36bf0c9d58bd1a7aa378ae4a5283b0d3271b725b Mon Sep 17 00:00:00 2001 From: Shane Delmore Date: Mon, 1 Feb 2016 09:50:18 -0800 Subject: Extend BigDecimal with Ordered for java interop --- test/junit/scala/math/BigDecimalTest.scala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/junit') diff --git a/test/junit/scala/math/BigDecimalTest.scala b/test/junit/scala/math/BigDecimalTest.scala index a9e2481f37..5de02cbe0c 100644 --- a/test/junit/scala/math/BigDecimalTest.scala +++ b/test/junit/scala/math/BigDecimalTest.scala @@ -260,4 +260,9 @@ class BigDecimalTest { testPrecision() testRounded() } + + @Test + def testIsComparable() { + assert(BigDecimal(0.1).isInstanceOf[java.lang.Comparable[_]]) + } } -- cgit v1.2.3 From 7137a3bfa6863860b7aee7920f74fb8257e66c01 Mon Sep 17 00:00:00 2001 From: Shane Delmore Date: Mon, 1 Feb 2016 09:50:35 -0800 Subject: Extend BigInt with Ordered for java interop --- src/library/scala/math/BigInt.scala | 23 ++++++----------------- test/files/run/numbereq.scala | 3 ++- test/junit/scala/math/BigIntTest.scala | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 test/junit/scala/math/BigIntTest.scala (limited to 'test/junit') diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index abc7371d9f..3ae3b9bf6c 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -109,7 +109,12 @@ object BigInt { * @author Martin Odersky * @version 1.0, 15/07/2003 */ -final class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericConversions with Serializable { +final class BigInt(val bigInteger: BigInteger) + extends ScalaNumber + with ScalaNumericConversions + with Serializable + with Ordered[BigInt] +{ /** Returns the hash code for this BigInt. */ override def hashCode(): Int = if (isValidLong) unifiedPrimitiveHashcode() @@ -176,22 +181,6 @@ final class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNum */ def compare (that: BigInt): Int = this.bigInteger.compareTo(that.bigInteger) - /** Less-than-or-equals comparison of BigInts - */ - def <= (that: BigInt): Boolean = compare(that) <= 0 - - /** Greater-than-or-equals comparison of BigInts - */ - def >= (that: BigInt): Boolean = compare(that) >= 0 - - /** Less-than of BigInts - */ - def < (that: BigInt): Boolean = compare(that) < 0 - - /** Greater-than comparison of BigInts - */ - def > (that: BigInt): Boolean = compare(that) > 0 - /** Addition of BigInts */ def + (that: BigInt): BigInt = new BigInt(this.bigInteger.add(that.bigInteger)) diff --git a/test/files/run/numbereq.scala b/test/files/run/numbereq.scala index 7ce4b23cf8..1f12d0643e 100644 --- a/test/files/run/numbereq.scala +++ b/test/files/run/numbereq.scala @@ -1,6 +1,7 @@ object Test { def mkNumbers(x: Int): List[AnyRef] = { - val base = List( + //Use explicit AnyRef to workaround known limitation of type inference with F-Bounds + val base = List[AnyRef]( BigDecimal(x), BigInt(x), new java.lang.Double(x.toDouble), diff --git a/test/junit/scala/math/BigIntTest.scala b/test/junit/scala/math/BigIntTest.scala new file mode 100644 index 0000000000..5a5694a775 --- /dev/null +++ b/test/junit/scala/math/BigIntTest.scala @@ -0,0 +1,16 @@ +package scala.math + +import java.math.{BigInteger => BI, MathContext => MC} + +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class BigIntTest { + + @Test + def testIsComparable() { + assert(BigInt(1).isInstanceOf[java.lang.Comparable[_]]) + } +} -- cgit v1.2.3