-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathZipWithArraySpliteratorTest.java
More file actions
61 lines (49 loc) · 2.08 KB
/
ZipWithArraySpliteratorTest.java
File metadata and controls
61 lines (49 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package spliterators.part3.exercise;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.StreamSupport;
import static org.junit.Assert.*;
public class ZipWithArraySpliteratorTest {
private List<Integer> listWithLessSize = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5));
private List<Integer> listWithSameSize = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
private List<Integer> listWithMoreSize = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14));
private Integer[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
@Test
public void testCount() {
final long expectedLess = listWithLessSize.size();
final long actualLess = StreamSupport
.stream(new ZipWithArraySpliterator<>(listWithLessSize.spliterator(), array), true)
.count();
assertEquals(expectedLess, actualLess);
final long expectedSame = listWithSameSize.size();
final long actualSame = StreamSupport
.stream(new ZipWithArraySpliterator<>(listWithSameSize.spliterator(), array), true)
.count();
assertEquals(expectedSame, actualSame);
final long expectedMore = array.length;
final long actualMore = StreamSupport
.stream(new ZipWithArraySpliterator<>(listWithMoreSize.spliterator(), array), true)
.count();
assertEquals(expectedMore, actualMore);
}
@Test
public void testSkip() {
long actual = StreamSupport
.stream(new ZipWithArraySpliterator<>(listWithSameSize.spliterator(), array), true)
.skip(2)
.mapToInt(Pair::getA)
.sum();
assertEquals(44, actual);
}
@Test
public void testLimit() {
long actual = StreamSupport
.stream(new ZipWithArraySpliterator<>(listWithSameSize.spliterator(), array), true)
.limit(4)
.mapToInt(Pair::getA)
.sum();
assertEquals(6, actual);
}
}