-
Notifications
You must be signed in to change notification settings - Fork 587
/
SelectInstancesOfIterableTest.java
121 lines (107 loc) · 3.88 KB
/
SelectInstancesOfIterableTest.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.lazy;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.math.IntegerSum;
import org.eclipse.collections.impl.math.Sum;
import org.eclipse.collections.impl.math.SumProcedure;
import org.eclipse.collections.impl.utility.LazyIterate;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SelectInstancesOfIterableTest extends AbstractLazyIterableTestCase
{
private static final Logger LOGGER = LoggerFactory.getLogger(SelectInstancesOfIterableTest.class);
@Override
protected <T> LazyIterable<T> newWith(T... elements)
{
return (LazyIterable<T>) LazyIterate.selectInstancesOf(FastList.newListWith(elements), Object.class);
}
@Test
public void forEach()
{
LazyIterable<Integer> select = new SelectInstancesOfIterable<>(FastList.newListWith(1, 2.0, 3, 4.0, 5), Integer.class);
Sum sum = new IntegerSum(0);
select.forEach(new SumProcedure<>(sum));
Assert.assertEquals(9, sum.getValue().intValue());
}
@Test
public void forEachWithIndex()
{
LazyIterable<Integer> select = new SelectInstancesOfIterable<>(FastList.newListWith(1, 2.0, 3, 4.0, 5), Integer.class);
Sum sum = new IntegerSum(0);
select.forEachWithIndex((object, index) -> {
sum.add(object);
sum.add(index);
LOGGER.info("value={} index={}", object, index);
});
Assert.assertEquals(12, sum.getValue().intValue());
}
@Override
@Test
public void iterator()
{
LazyIterable<Integer> select = new SelectInstancesOfIterable<>(FastList.newListWith(1, 2.0, 3, 4.0, 5), Integer.class);
Sum sum = new IntegerSum(0);
for (Integer each : select)
{
sum.add(each);
}
Assert.assertEquals(9, sum.getValue().intValue());
}
@Test
public void forEachWith()
{
LazyIterable<Integer> select = new SelectInstancesOfIterable<>(FastList.newListWith(1, 2.0, 3, 4.0, 5), Integer.class);
Sum sum = new IntegerSum(0);
select.forEachWith((each, aSum) -> aSum.add(each), sum);
Assert.assertEquals(9, sum.getValue().intValue());
}
@Override
@Test
public void min_null_throws()
{
// Impossible for SelectInstancesOfIterable to contain null
super.min_null_throws();
}
@Override
@Test
public void max_null_throws()
{
// Impossible for SelectInstancesOfIterable to contain null
super.max_null_throws();
}
@Override
@Test
public void min_null_throws_without_comparator()
{
// Impossible for SelectInstancesOfIterable to contain null
super.min_null_throws_without_comparator();
}
@Override
@Test
public void max_null_throws_without_comparator()
{
// Impossible for SelectInstancesOfIterable to contain null
super.max_null_throws_without_comparator();
}
@Override
@Test
public void distinct()
{
super.distinct();
LazyIterable<Double> iterable = new SelectInstancesOfIterable<>(FastList.newListWith(3.0, 2.0, 3, 2.0, 4.0, 5, 1.0, 3.0, 1.0, 5.0), Double.class);
Assert.assertEquals(
FastList.newListWith(3.0, 2.0, 4.0, 1.0, 5.0),
iterable.distinct().toList());
}
}