diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-09-21 15:53:52 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2015-09-21 15:53:52 +0200 |
commit | 7eadd684678611dc0f6710f9fdd14ff52bf8fb78 (patch) | |
tree | 4e625c025ecf8ce5a9a4043dc13c77e54ba884f1 /test/files/scalacheck | |
parent | 7f1defca22b719b16814626b0218d12e24d5f149 (diff) | |
parent | 00d3f103b3db5530bfbf6b565843d0938a3cef48 (diff) | |
download | scala-7eadd684678611dc0f6710f9fdd14ff52bf8fb78.tar.gz scala-7eadd684678611dc0f6710f9fdd14ff52bf8fb78.tar.bz2 scala-7eadd684678611dc0f6710f9fdd14ff52bf8fb78.zip |
Merge pull request #4716 from Ichoran/issue/9388
SI-9388 Fix Range behavior around Int.MaxValue
Diffstat (limited to 'test/files/scalacheck')
-rw-r--r-- | test/files/scalacheck/range.scala | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index 493083a51f..ac24b52f8d 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -134,7 +134,22 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { val expected = r.length match { case 0 => 0 case 1 => r.head - case _ => ((r.head + r.last).toLong * r.length / 2).toInt + case x if x < 1000 => + // Explicit sum, to guard against having the same mistake in both the + // range implementation and test implementation of sum formula. + // (Yes, this happened before.) + var i = r.head + var s = 0L + var n = x + while (n > 0) { + s += i + i += r.step + n -= 1 + } + s.toInt + case _ => + // Make sure head + last doesn't overflow! + ((r.head.toLong + r.last) * r.length / 2).toInt } // println("size: " + r.length) // println("expected: " + expected) |