-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathRectangleSpliteratorTest.java
More file actions
42 lines (32 loc) · 1.24 KB
/
RectangleSpliteratorTest.java
File metadata and controls
42 lines (32 loc) · 1.24 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
package spliterators.part1.exercise;
import org.junit.Test;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class RectangleSpliteratorTest {
private int[][] getRandomArray(int count, int length) {
final int[][] result = new int[count][length];
for (int i = 0; i < count; i++)
for (int j = 0; j < length; j++)
result[i][j] = j;
return result;
}
@Test
public void parallelAndSeqGiveSameResults() {
final int[][] randomArray = getRandomArray(4, 4);
long count = StreamSupport.stream(new RectangleSpliterator(randomArray), true)
.count();
long count2 = StreamSupport.stream(new RectangleSpliterator(randomArray), true)
.skip(7)
.count();
int n = 7;
List<Integer> result2 = StreamSupport.stream(new RectangleSpliterator(randomArray), true)
.skip(n)
.collect(Collectors.toList());
assertThat(count, is(16L));
assertThat(count2, is(9L));
assertThat(result2.get(0), is(randomArray[0][n % randomArray[0].length]));
}
}