-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathZipWithIndexDoubleSpliteratorTest.java
More file actions
87 lines (66 loc) · 2.55 KB
/
ZipWithIndexDoubleSpliteratorTest.java
File metadata and controls
87 lines (66 loc) · 2.55 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package spliterators.part2.exercise;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.junit.Assert.*;
public class ZipWithIndexDoubleSpliteratorTest {
final double[] array = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
@Test
public void testCount() {
Spliterator.OfDouble spliterator = Arrays.spliterator(array);
final long expected = 6;
long actual = StreamSupport
.stream(new ZipWithIndexDoubleSpliterator(spliterator), true)
.count();
assertEquals(expected, actual);
}
@Test
public void testToList() {
Spliterator.OfDouble spliterator = Arrays.spliterator(array);
final List<Double> expected = Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
List<Double> actual = StreamSupport
.stream(new ZipWithIndexDoubleSpliterator(spliterator), true)
.map(IndexedDoublePair::getValue)
.collect(Collectors.toList());
assertEquals(expected, actual);
}
@Test
public void testPaired() {
Spliterator.OfDouble spliterator = Arrays.spliterator(array);
final List<IndexedDoublePair> expected = Arrays.asList(
new IndexedDoublePair(0, 1.0),
new IndexedDoublePair(1, 2.0),
new IndexedDoublePair(2, 3.0),
new IndexedDoublePair(3, 4.0),
new IndexedDoublePair(4, 5.0),
new IndexedDoublePair(5, 6.0)
);
List<IndexedDoublePair> actual = StreamSupport
.stream(new ZipWithIndexDoubleSpliterator(spliterator), true)
.collect(Collectors.toList());
assertEquals(expected, actual);
}
@Test
public void testSkip() {
Spliterator.OfDouble spliterator = Arrays.spliterator(array);
double actual = StreamSupport
.stream(new ZipWithIndexDoubleSpliterator(spliterator), true)
.skip(3)
.mapToDouble(IndexedDoublePair::getValue)
.sum();
assertTrue(15.0 == actual);
}
@Test
public void testLimit() {
Spliterator.OfDouble spliterator = Arrays.spliterator(array);
double actual = StreamSupport
.stream(new ZipWithIndexDoubleSpliterator(spliterator), true)
.limit(3)
.mapToDouble(IndexedDoublePair::getValue)
.sum();
assertTrue(6.0 == actual);
}
}