From bf65e48526e022a520d8c88f8a4a290fd6494daa Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 30 Jun 2011 21:38:03 +0000 Subject: Fix for unfortunate bug in Range.init. --- src/library/scala/collection/immutable/Range.scala | 2 +- test/files/scalacheck/range.scala | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala index ed4f4615c2..804c67527a 100644 --- a/src/library/scala/collection/immutable/Range.scala +++ b/src/library/scala/collection/immutable/Range.scala @@ -128,7 +128,7 @@ extends IndexedSeq[Int] if (isEmpty) Nil.init - dropRight(length - 1) + dropRight(1) } /** Creates a new range containing all the elements of this range except the first one. diff --git a/test/files/scalacheck/range.scala b/test/files/scalacheck/range.scala index 6a0e83a47d..56295f204c 100644 --- a/test/files/scalacheck/range.scala +++ b/test/files/scalacheck/range.scala @@ -130,6 +130,13 @@ abstract class RangeTest(kind: String) extends Properties("Range "+kind) { (t.size == (0 max x min r.size) && t.start == r.start && t.step == r.step) :| str(r)+" / "+str(t)+": "+x } + property("init") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r))) { r => + (r.size == 0) || { + val t = r.init + (t.size + 1 == r.size) && (t.isEmpty || t.head == r.head) + } + } + property("takeWhile") = forAll(myGen suchThat (r => expectedSize(r).toInt == expectedSize(r)), arbInt.arbitrary) { (r, x) => val t = (if (r.step > 0) r takeWhile (_ <= x) else r takeWhile(_ >= x)) if (r.size == 0) { -- cgit v1.2.3