Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
stream/src/test/java/com/annimon/stream/doublestreamtests/FindLastTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.annimon.stream.doublestreamtests; | ||
|
||
import com.annimon.stream.DoubleStream; | ||
import org.junit.Test; | ||
import static com.annimon.stream.test.hamcrest.OptionalDoubleMatcher.hasValue; | ||
import static com.annimon.stream.test.hamcrest.OptionalDoubleMatcher.isEmpty; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public final class FindLastTest { | ||
|
||
@Test | ||
public void testFindLast() { | ||
assertThat(DoubleStream.of(0.012, 10.347, 3.039, 19.84, 100d).findLast(), | ||
hasValue(100d)); | ||
|
||
assertThat(DoubleStream.of(100d).findLast(), | ||
hasValue(100d)); | ||
|
||
assertThat(DoubleStream.empty().findLast(), | ||
isEmpty()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
stream/src/test/java/com/annimon/stream/intstreamtests/FindLastTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.annimon.stream.intstreamtests; | ||
|
||
import com.annimon.stream.IntStream; | ||
import org.junit.Test; | ||
import static com.annimon.stream.test.hamcrest.OptionalIntMatcher.hasValue; | ||
import static com.annimon.stream.test.hamcrest.OptionalIntMatcher.isEmpty; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public final class FindLastTest { | ||
|
||
@Test | ||
public void testFindLast() { | ||
assertThat(IntStream.of(3, 10, 19, 4, 50).findLast(), | ||
hasValue(50)); | ||
|
||
assertThat(IntStream.of(50).findLast(), | ||
hasValue(50)); | ||
|
||
assertThat(IntStream.empty().findFirst(), | ||
isEmpty()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
stream/src/test/java/com/annimon/stream/longstreamtests/FindLastTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.annimon.stream.longstreamtests; | ||
|
||
import com.annimon.stream.LongStream; | ||
import org.junit.Test; | ||
import static com.annimon.stream.test.hamcrest.OptionalLongMatcher.hasValue; | ||
import static com.annimon.stream.test.hamcrest.OptionalLongMatcher.isEmpty; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public final class FindLastTest { | ||
|
||
@Test | ||
public void testFindLast() { | ||
assertThat(LongStream.of(3, 10, 19, 4, 50).findLast(), | ||
hasValue(50L)); | ||
|
||
assertThat(LongStream.of(50).findLast(), | ||
hasValue(50L)); | ||
|
||
assertThat(LongStream.empty().findLast(), | ||
isEmpty()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
stream/src/test/java/com/annimon/stream/streamtests/FindLastTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.annimon.stream.streamtests; | ||
|
||
import com.annimon.stream.Functions; | ||
import com.annimon.stream.Optional; | ||
import com.annimon.stream.Stream; | ||
import com.annimon.stream.test.hamcrest.OptionalMatcher; | ||
import org.junit.Test; | ||
import static com.annimon.stream.test.hamcrest.OptionalMatcher.isPresent; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public final class FindLastTest { | ||
|
||
@Test | ||
public void testFindLast() { | ||
Optional<Integer> result = Stream.rangeClosed(0, 10) | ||
.findLast(); | ||
assertThat(result, isPresent()); | ||
assertNotNull(result.get()); | ||
assertEquals(10, (int) result.get()); | ||
} | ||
|
||
@Test | ||
public void testFindLastOnEmptyStream() { | ||
assertThat(Stream.empty().findLast(), OptionalMatcher.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testFindLastAfterFiltering() { | ||
Optional<Integer> result = Stream.range(1, 100) | ||
.filter(Functions.remainder(6)) | ||
.findLast(); | ||
|
||
assertThat(result, isPresent()); | ||
assertNotNull(result.get()); | ||
assertEquals(96, (int) result.get()); | ||
} | ||
} |