5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.openjdk.tests.java.util.stream;
24
25 import java.util.Comparators;
26 import java.util.stream.LambdaTestHelpers;
27 import java.util.stream.OpTestCase;
28 import java.util.stream.StreamTestDataProvider;
29 import org.testng.annotations.Test;
30
31 import java.util.Iterator;
32 import java.util.Comparator;
33 import java.util.concurrent.atomic.AtomicInteger;
34 import java.util.function.Function;
35 import java.util.function.Supplier;
36 import java.util.function.UnaryOperator;
37 import java.util.Spliterator;
38 import java.util.stream.Stream;
39 import java.util.stream.TestData;
40
41 import static org.testng.Assert.assertEquals;
42 import static org.testng.Assert.assertTrue;
43
44 /**
45 * SequentialOpTest
92 assertTrue(data.size() == 0 || counter.get() > 0);
93 }
94 }
95 }
96
97 @SuppressWarnings({"rawtypes", "unchecked"})
98 @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
99 public void testMixedSeqPar(String name, TestData.OfRef<Integer> data) {
100 Function<Integer, Integer> id = LambdaTestHelpers.identity();
101 UnaryOperator<Stream<Integer>>[] changers
102 = new UnaryOperator[] {
103 (UnaryOperator<Stream<Integer>>) s -> s,
104 (UnaryOperator<Stream<Integer>>) s -> s.sequential(),
105 (UnaryOperator<Stream<Integer>>) s -> s.parallel(),
106 (UnaryOperator<Stream<Integer>>) s -> s.unordered()
107 };
108 UnaryOperator<Stream<Integer>>[] stuff
109 = new UnaryOperator[] {
110 (UnaryOperator<Stream<Integer>>) s -> s,
111 (UnaryOperator<Stream<Integer>>) s -> s.map(id),
112 (UnaryOperator<Stream<Integer>>) s -> s.sorted(Comparators.naturalOrder()),
113 (UnaryOperator<Stream<Integer>>) s -> s.map(id).sorted(Comparators.naturalOrder()).map(id),
114 (UnaryOperator<Stream<Integer>>) s -> s.filter(LambdaTestHelpers.pEven).sorted(Comparators.naturalOrder()).map(id),
115 };
116
117 for (int c1Index = 0; c1Index < changers.length; c1Index++) {
118 setContext("c1Index", c1Index);
119 UnaryOperator<Stream<Integer>> c1 = changers[c1Index];
120 for (int s1Index = 0; s1Index < stuff.length; s1Index++) {
121 setContext("s1Index", s1Index);
122 UnaryOperator<Stream<Integer>> s1 = stuff[s1Index];
123 for (int c2Index = 0; c2Index < changers.length; c2Index++) {
124 setContext("c2Index", c2Index);
125 UnaryOperator<Stream<Integer>> c2 = changers[c2Index];
126 for (int s2Index = 0; s2Index < stuff.length; s2Index++) {
127 setContext("s2Index", s2Index);
128 UnaryOperator<Stream<Integer>> s2 = stuff[s2Index];
129 UnaryOperator<Stream<Integer>> composed = s -> s2.apply(c2.apply(s1.apply(c1.apply(s))));
130 exerciseOps(data, composed);
131 }
132 }
133 }
134 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.openjdk.tests.java.util.stream;
24
25 import java.util.stream.LambdaTestHelpers;
26 import java.util.stream.OpTestCase;
27 import java.util.stream.StreamTestDataProvider;
28 import org.testng.annotations.Test;
29
30 import java.util.Iterator;
31 import java.util.Comparator;
32 import java.util.concurrent.atomic.AtomicInteger;
33 import java.util.function.Function;
34 import java.util.function.Supplier;
35 import java.util.function.UnaryOperator;
36 import java.util.Spliterator;
37 import java.util.stream.Stream;
38 import java.util.stream.TestData;
39
40 import static org.testng.Assert.assertEquals;
41 import static org.testng.Assert.assertTrue;
42
43 /**
44 * SequentialOpTest
91 assertTrue(data.size() == 0 || counter.get() > 0);
92 }
93 }
94 }
95
96 @SuppressWarnings({"rawtypes", "unchecked"})
97 @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
98 public void testMixedSeqPar(String name, TestData.OfRef<Integer> data) {
99 Function<Integer, Integer> id = LambdaTestHelpers.identity();
100 UnaryOperator<Stream<Integer>>[] changers
101 = new UnaryOperator[] {
102 (UnaryOperator<Stream<Integer>>) s -> s,
103 (UnaryOperator<Stream<Integer>>) s -> s.sequential(),
104 (UnaryOperator<Stream<Integer>>) s -> s.parallel(),
105 (UnaryOperator<Stream<Integer>>) s -> s.unordered()
106 };
107 UnaryOperator<Stream<Integer>>[] stuff
108 = new UnaryOperator[] {
109 (UnaryOperator<Stream<Integer>>) s -> s,
110 (UnaryOperator<Stream<Integer>>) s -> s.map(id),
111 (UnaryOperator<Stream<Integer>>) s -> s.sorted(Comparator.naturalOrder()),
112 (UnaryOperator<Stream<Integer>>) s -> s.map(id).sorted(Comparator.naturalOrder()).map(id),
113 (UnaryOperator<Stream<Integer>>) s -> s.filter(LambdaTestHelpers.pEven).sorted(Comparator.naturalOrder()).map(id),
114 };
115
116 for (int c1Index = 0; c1Index < changers.length; c1Index++) {
117 setContext("c1Index", c1Index);
118 UnaryOperator<Stream<Integer>> c1 = changers[c1Index];
119 for (int s1Index = 0; s1Index < stuff.length; s1Index++) {
120 setContext("s1Index", s1Index);
121 UnaryOperator<Stream<Integer>> s1 = stuff[s1Index];
122 for (int c2Index = 0; c2Index < changers.length; c2Index++) {
123 setContext("c2Index", c2Index);
124 UnaryOperator<Stream<Integer>> c2 = changers[c2Index];
125 for (int s2Index = 0; s2Index < stuff.length; s2Index++) {
126 setContext("s2Index", s2Index);
127 UnaryOperator<Stream<Integer>> s2 = stuff[s2Index];
128 UnaryOperator<Stream<Integer>> composed = s -> s2.apply(c2.apply(s1.apply(c1.apply(s))));
129 exerciseOps(data, composed);
130 }
131 }
132 }
133 }
|