diff options
author | Paul Phillips <paulp@improving.org> | 2010-11-01 14:26:28 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-11-01 14:26:28 +0000 |
commit | 00b42b18ed462db89956de881bbc13740cd8ba82 (patch) | |
tree | 6be826d0465cd687d17ac98daf08f5a945ef69b2 /test | |
parent | 6beaf28e6d25535ac9a1d4abe195bb32ebff8c15 (diff) | |
download | scala-00b42b18ed462db89956de881bbc13740cd8ba82.tar.gz scala-00b42b18ed462db89956de881bbc13740cd8ba82.tar.bz2 scala-00b42b18ed462db89956de881bbc13740cd8ba82.zip |
Took a step back and massively simplified Range.
all the boundary conditions I'm aware of, including not yet reported
ones such as
scala> 5 until 5 last
res0: Int = 4
and
scala> 1073741823 to Int.MaxValue by (1 << 24) size
res0: Int = 65
scala> 1073741823 to Int.MaxValue by (1 << 24) drop 100 size
res1: Int = 256
Also includes conformance improvements (e.g. 5 until 5 init should throw
an exception, not return empty) and general improvements (e.g. 1 to 10
tail should return a Range.) Will close associated tickets such as #3232
after I complete similar work on NumericRange. Review by community.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/bug3232.scala | 21 | ||||
-rw-r--r-- | test/files/scalacheck/range.scala | 17 |
2 files changed, 37 insertions, 1 deletions
diff --git a/test/files/run/bug3232.scala b/test/files/run/bug3232.scala new file mode 100644 index 0000000000..acb1a1e0e9 --- /dev/null +++ b/test/files/run/bug3232.scala @@ -0,0 +1,21 @@ +object Test { + // some maximally sized ranges + val r1 = 0 until Int.MaxValue + val r2 = 1 to Int.MaxValue + val r3 = Int.MinValue to -2 + val r4 = Int.MinValue until -1 + + // some exceptional conditions + val e1 = () => (0 to Int.MaxValue).length + val e2 = () => (5 until 5).last + + def main(args: Array[String]): Unit = { + List(r1, r2, r3, r4) foreach (x => assert(x.length == Int.MaxValue)) + + // exception required + List(e1, e2) foreach { f => + try { f() ; assert(false) } + catch { case _ => () } + } + } +} diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index b14177e38b..6a0e83a47d 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -182,10 +182,25 @@ object SmallValuesRange extends RangeTest("smallValues") { override def myGen = genSmallRange } +object TooLargeRange extends Properties("Too Large Range") { + val genTooLargeStart = for { + start <- choose(-Int.MinValue, 0) + } yield start + + property("Too large range throws exception") = forAll(genTooLargeStart) { start => + try { + val r = Range.inclusive(start, Int.MaxValue, 1) + println("how here? r = " + r.toString) + false + } + catch { case _: IllegalArgumentException => true } + } +} + object Test extends Properties("Range") { import org.scalacheck.{ Test => STest } - List(NormalRangeTest, InclusiveRangeTest, ByOneRangeTest, InclusiveByOneRangeTest) foreach { ps => + List(NormalRangeTest, InclusiveRangeTest, ByOneRangeTest, InclusiveByOneRangeTest, TooLargeRange) foreach { ps => STest.checkProperties(STest.Params(testCallback = ConsoleReporter(0)), ps) } } |