From d4f664c98364858c319b599caa1cdbb68030440a Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 27 May 2014 12:06:56 -0700 Subject: SI-8475 GroupedIterator is also lazy when padded This is the related case which dnlgtm in the previous fix. The old code seems to be tilting for laziness, but we have to fill the buffer with the current group anyway, so there is no reason to be coy about calling ArrayBuffer.length. --- test/junit/scala/collection/IteratorTest.scala | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/junit') diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala index cb7cbb40bc..b7a9805c9f 100644 --- a/test/junit/scala/collection/IteratorTest.scala +++ b/test/junit/scala/collection/IteratorTest.scala @@ -17,4 +17,12 @@ class IteratorTest { slidingIt.next assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) } + + @Test def groupedIteratorIsLazyWhenPadded(): Unit = { + var counter = 0 + def it = new Iterator[Int] { var i = 0 ; def hasNext = { counter = i; true } ; def next = { i += 1; i } } + val slidingIt = it sliding 2 withPadding -1 + slidingIt.next + assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) + } } -- cgit v1.2.3