Implement Stack.takeWhile()
Requesting review @motlin. Thanks!
The implementation is probably good, but the implementations of StackIterable.takeWhile() have no test coverage.
I tried writing these tests in StackIteratable.java
@Test
public void takeWhile(){
StackIterable<Integer> stack = this.newStackWith(1, 2, 3, 4, 5, 6, 7);
assertEquals( this.newStackWith(), stack.takeWhile(Predicates.alwaysFalse()));
assertEquals(this.newStackWith(1), stack.takeWhile(each -> each <= 1));
assertEquals(this.newStackWith(1, 2), stack.takeWhile(each -> each <= 2));
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6), stack.takeWhile(each -> each <= stack.size() - 1));
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6, 7), stack.takeWhile(each -> each <= stack.size()));
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6, 7), stack.takeWhile(Predicates.alwaysTrue()));
}
but they return
[ERROR] Failures:
[ERROR] ImmutableArrayStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]>
[ERROR] ArrayStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]>
[ERROR] SynchronizedStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]>
[ERROR] UnmodifiableStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]>
What might be the problem?
[ERROR] Failures: [ERROR] ImmutableArrayStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]> [ERROR] ArrayStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]> [ERROR] SynchronizedStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]> [ERROR] UnmodifiableStackTest>StackIterableTestCase.takeWhile:226 expected:<[1]> but was:<[]>
@motlin When Stack.takeWhile() was implemented using LazyIterator, returned Stack was always null. Do we have an issue with LazyIterator.takeWhile()?
LGTM now, probably just needs the two commits squashed into one.
Done.