-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Stack.takeWhile() #1639
base: master
Are you sure you want to change the base?
Conversation
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
but they return
What might be the problem? |
3d70e30
to
8f4f458
Compare
@motlin When Stack.takeWhile() was implemented using LazyIterator, returned Stack was always null. Do we have an issue with LazyIterator.takeWhile()? |
8f4f458
to
6fad5ef
Compare
6fad5ef
to
18bdeca
Compare
LGTM now, probably just needs the two commits squashed into one. |
18bdeca
to
af72a10
Compare
Done. |
|
||
public ReverseIterable<T> asReversed() | ||
{ | ||
return ReverseIterable.adapt(this.toList()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add asReversed here. It's not part of the public API (no @OverRide) here. as* methods are supposed to be O(1) and this implementation is O(2). Anyway, it's not necessary. We can use asLazy() instead.
assertEquals(this.newStackWith(1, 2), stack.takeWhile(Predicates.lessThanOrEqualTo(2))); | ||
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6), stack.takeWhile(Predicates.lessThanOrEqualTo(stack.size() - 1))); | ||
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6, 7), stack.takeWhile(Predicates.lessThanOrEqualTo(stack.size()))); | ||
assertEquals(this.newStackWith(1, 2, 3, 4, 5, 6, 7), stack.takeWhile(Predicates.alwaysTrue())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there aren't any tests of empty stacks, so ImmutableEmptyStack won't have coverage.
No description provided.