-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathRectangleSpliteratorTest.java
38 lines (29 loc) · 1.11 KB
/
RectangleSpliteratorTest.java
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
package part1;
import org.junit.Assert;
import org.junit.Test;
import spliterators.part1.exercise.RectangleSpliterator;
import java.util.Arrays;
import java.util.stream.StreamSupport;
/**
* Created by nikita on 4/11/2017.
*/
public class RectangleSpliteratorTest {
private int[][] getRandomArray(final int outerLength, final int innerLenght) {
final int[][] result = new int[outerLength][innerLenght];
for (int i = 0; i < outerLength; i++) {
for(int j = 0; j< innerLenght; j++){
result[i][j] = j;
}
}
return result;
}
@Test
public void trySplit(){
final int[][] array = getRandomArray(2,4);
final long actual = StreamSupport.stream(new RectangleSpliterator(array), true).count();
final long expected = Arrays.stream(array).parallel().flatMapToInt(Arrays::stream).count();
final long actual2 = StreamSupport.stream(new RectangleSpliterator(array), true).skip(5).count();
Assert.assertEquals(expected, actual);
Assert.assertEquals(3, actual2);
}
}