-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathZipWithArraySpliteratorTest.java
More file actions
45 lines (35 loc) · 1.7 KB
/
ZipWithArraySpliteratorTest.java
File metadata and controls
45 lines (35 loc) · 1.7 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
package spliterators.part3.exercise;
import org.junit.Test;
import java.util.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
public class ZipWithArraySpliteratorTest {
private Integer[] array = {1, 2, 3};
private Spliterator<Integer> arraySpltr = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6}).spliterator();
private ZipWithArraySpliterator<Integer, Integer> zipSpltr = new ZipWithArraySpliterator<>(arraySpltr, array);
@Test
public void testEstimatingSizeForFirstCreating() {
int expected = 6;
int actual = (int) zipSpltr.estimateSize();
assertThat(actual, is(expected));
}
@Test
public void testFirstlySplitting() {
Spliterator<Pair<Integer, Integer>> firstSpl = zipSpltr.trySplit();
Spliterator<Pair<Integer, Integer>> secondSpl = zipSpltr;
assertThat((int) firstSpl.estimateSize(), is(3));
assertThat((int) secondSpl.estimateSize(), is(6));
List<Pair<Integer, Integer>> expectedFirstListOfSpl = Arrays.asList(
new Pair<>(1, 1),
new Pair<>(2, 2),
new Pair<>(3, 3));
List<Pair<Integer, Integer>> actualFirstListOfSpl = new ArrayList<>();
while (firstSpl.tryAdvance(actualFirstListOfSpl::add)) ;
assertEquals(expectedFirstListOfSpl, actualFirstListOfSpl);
List<Pair<Integer, Integer>> expectedSecondListOfSpl = Collections.emptyList();
List<Pair<Integer, Integer>> actualSecondListOfSpl = new ArrayList<>();
while (secondSpl.tryAdvance(actualSecondListOfSpl::add)) ;
assertEquals(expectedSecondListOfSpl, actualSecondListOfSpl);
}
}