diff options
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 2 | ||||
-rw-r--r-- | test/files/run/unittest_iterator.scala | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index ba622d5e5a..daa6a59f3b 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -827,7 +827,7 @@ trait Iterator[+A] extends TraversableOnce[A] { // if 0 elements are requested, or if the number of newly obtained // elements is less than the gap between sequences, we are done. def deliver(howMany: Int) = { - (howMany > 0 && len > gap) && { + (howMany > 0 && (isFirst || len > gap)) && { if (!isFirst) buffer trimStart (step min prevSize) diff --git a/test/files/run/unittest_iterator.scala b/test/files/run/unittest_iterator.scala index 28a548160f..21dc64c3c5 100644 --- a/test/files/run/unittest_iterator.scala +++ b/test/files/run/unittest_iterator.scala @@ -1,6 +1,5 @@ // Some iterator grouped/sliding unit tests -object Test -{ +object Test { def it = (1 to 10).iterator def assertThat[T](expectedLength: Int, expectedLast: Seq[T])(it: Iterator[Seq[T]]) { val xs = it.toList @@ -34,7 +33,11 @@ object Test assertThat(2, List(9, 10, -1, -1, -1)) { it.sliding(5, 8) withPadding -1 } assertThat(1, (1 to 5).toList) { it.sliding(5, 8) withPartial false } - // make sure it throws past th end + // larger step than window + assertThat(5, List(9)) { it.sliding(1, 2) } + assertThat(3, List(9, 10)) { it.sliding(2, 4) } + + // make sure it throws past the end val thrown = try { val it = List(1,2,3).sliding(2) it.next |