summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTobias Schlatter <tobias@meisch.ch>2016-12-12 14:45:47 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2016-12-12 14:45:47 +0100
commit738ac6d7d3902767cc4cd5820fe83632e558f049 (patch)
tree13bb9049714689485d486e6a31f9bd7db4bfd9b4 /test
parent264cc5f20cd9a6b9c6d414dfea696de1b8608dc5 (diff)
downloadscala-738ac6d7d3902767cc4cd5820fe83632e558f049.tar.gz
scala-738ac6d7d3902767cc4cd5820fe83632e558f049.tar.bz2
scala-738ac6d7d3902767cc4cd5820fe83632e558f049.zip
SI-10086 NumericRange.min|max with custom Integral (#5575)
SI-10086 NumericRange.min|max with custom Integral
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/collection/immutable/RangeConsistencyTest.scala39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/junit/scala/collection/immutable/RangeConsistencyTest.scala b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
index 760498c162..a997fd14ab 100644
--- a/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
+++ b/test/junit/scala/collection/immutable/RangeConsistencyTest.scala
@@ -172,4 +172,43 @@ class RangeConsistencyTest {
assert(r.sum(possiblyNotDefaultNumeric) == Int.MinValue)
assert(nr.sum(possiblyNotDefaultNumeric) == Int.MinValue)
}
+
+ @Test
+ def test_SI10086() {
+ implicit val customIntegral =
+ new Numeric.IntIsIntegral with Ordering.IntOrdering {}
+
+ val nr = NumericRange(1, 10, 1)
+ assert(nr.min == 1)
+ assert(nr.max == 9)
+
+ // Also test with custom ordering.
+ assert(nr.min(customIntegral.reverse) == 9)
+ assert(nr.max(customIntegral.reverse) == 1)
+
+ case class A(v: Int)
+
+ implicit object aIsIntegral extends scala.math.Integral[A] {
+ def compare(x: A, y: A): Int = x.v.compare(y.v)
+ def fromInt(x: Int): A = A(x)
+ def minus(x: A, y: A): A = A(x.v - y.v)
+ def negate(x: A): A = A(-x.v)
+ def plus(x: A, y: A): A = A(x.v + y.v)
+ def times(x: A, y: A): A = A(x.v * y.v)
+ def quot(x: A, y: A): A = A(x.v / y.v)
+ def rem(x: A, y: A): A = A(x.v % y.v)
+ def toDouble(x: A): Double = x.v.toDouble
+ def toFloat(x: A): Float = x.v.toFloat
+ def toInt(x: A): Int = x.v
+ def toLong(x: A): Long = x.v.toLong
+ }
+
+ val r = NumericRange(A(1), A(10), A(1))
+ assert(r.min == A(1))
+ assert(r.max == A(9))
+
+ // Also test with custom ordering.
+ assert(r.min(aIsIntegral.reverse) == A(9))
+ assert(r.max(aIsIntegral.reverse) == A(1))
+ }
}