1a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin/* 2a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 5a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * This code is free software; you can redistribute it and/or modify it 6a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * under the terms of the GNU General Public License version 2 only, as 7a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * published by the Free Software Foundation. 8a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 9a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * This code is distributed in the hope that it will be useful, but WITHOUT 10a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * version 2 for more details (a copy is included in the LICENSE file that 13a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * accompanied this code). 14a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 15a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * You should have received a copy of the GNU General Public License version 16a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 2 along with this work; if not, write to the Free Software Foundation, 17a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 19a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * or visit www.oracle.com if you need additional information or have any 21a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * questions. 22a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin */ 23a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinpackage org.openjdk.tests.java.util.stream; 24a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 25289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.DoubleStreamTestDataProvider; 26289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.IntStreamTestDataProvider; 27289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.LambdaTestHelpers; 28289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.LongStreamTestDataProvider; 29289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.OpTestCase; 30289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.StreamTestDataProvider; 31289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport org.openjdk.testlib.java.util.stream.TestData; 32289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkin 33a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport org.testng.annotations.Test; 34a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 35a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.*; 36a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.function.Function; 37289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport java.util.stream.BaseStream; 38289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport java.util.stream.Stream; 39289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport java.util.stream.IntStream; 40289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport java.util.stream.LongStream; 41289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport java.util.stream.DoubleStream; 42a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 43289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport static org.openjdk.testlib.java.util.stream.LambdaTestHelpers.*; 44a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport static org.testng.Assert.assertEquals; 45a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 46a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 47a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin/** 48a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * ToArrayOpTest 49a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 50a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin */ 51a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin@Test 52a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinpublic class ToArrayOpTest extends OpTestCase { 53a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 54a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testToArray() { 55a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertCountSum(Arrays.asList(countTo(0).stream().toArray()), 0, 0); 56a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertCountSum(Arrays.asList(countTo(10).stream().toArray()), 10, 55); 57a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 58a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 59a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 60a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testOps(String name, TestData.OfRef<Integer> data) { 61a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.toArray()); 62a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 63a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 64a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 65a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testOpsWithMap(String name, TestData.OfRef<Integer> data) { 66a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 67a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 68a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 69a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Object[] objects = exerciseTerminalOps(data, s -> s.map(i -> (Integer) (i + i)), s -> s.toArray()); 70a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size()); 71a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 72a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 73a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 74a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testOpsWithSorted(String name, TestData.OfRef<Integer> data) { 75a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 76a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 77a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 78a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Object[] objects = exerciseTerminalOps(data, s -> s.sorted(), s -> s.toArray()); 79a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size()); 80a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 81a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 82a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 83a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testOpsWithFlatMap(String name, TestData.OfRef<Integer> data) { 84a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Double the size of the source 85a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 86a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 87a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Object[] objects = exerciseTerminalOps(data, 88a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.flatMap(e -> Arrays.stream(new Object[] { e, e })), 89a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.toArray()); 90a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size() * 2); 91a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 92a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 93a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 94a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testOpsWithFilter(String name, TestData.OfRef<Integer> data) { 95a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Reduce the size of the source 96a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 97a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 98a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.filter(LambdaTestHelpers.pEven), s -> s.toArray()); 99a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 100a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 101a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testAsArrayWithType() { 102a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps( 103a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin TestData.Factory.ofCollection("", Arrays.asList(1.1, 2.2, 3.4, 4.4)), 104a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> // First pipeline slice using Object[] with Double elements 105a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s.sorted() 106a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Second pipeline slice using Integer[] with Integer elements 107a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .map((Double d) -> Integer.valueOf(d.intValue())).sorted(), 108a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.toArray(Integer[]::new)); 109a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 110a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 111a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<Stream<Integer>, Stream<Integer>>> uniqueAndSortedPermutations = 112a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 113a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 114a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 115a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted(), 116a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 117a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 118a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 119a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 120a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDistinctAndSortedPermutations(String name, TestData.OfRef<Integer> data) { 121a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<Stream<Integer>, Stream<Integer>> f : uniqueAndSortedPermutations) { 122a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 123a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 124a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Integer[] is = exerciseTerminalOps(data, f, s -> s.toArray(Integer[]::new)); 125a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(is.getClass(), Integer[].class); 126a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 127a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Number[] ns = exerciseTerminalOps(data, f, s -> s.toArray(Number[]::new)); 128a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(ns.getClass(), Number[].class); 129a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 130a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin if (data.size() > 0) { 131a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Exception caught = null; 132a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin try { 133a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray(String[]::new)); 134a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } catch (Exception e) { 135a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin caught = e; 136a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 137a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(caught != null); 138a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(caught.getClass(), ArrayStoreException.class); 139a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 140a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 141a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 142a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 143a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<Stream<Integer>, Stream<Integer>>> statefulOpPermutations = 144a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 145a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.limit(10), 146a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 147a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 148a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 149a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 150a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private <T extends Object> ResultAsserter<T[]> statefulOpResultAsserter(TestData.OfRef<Integer> data) { 151a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin return (act, exp, ord, par) -> { 152a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin if (par) { 153a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin if (!data.isOrdered()) { 154a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Relax the checking if the data source is unordered 155a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // It is not exactly possible to determine if the limit 156a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // operation is present and if it is before or after 157a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // the sorted operation 158a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // If the limit operation is present and before the sorted 159a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // operation then the sub-set output after limit is a 160a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // non-deterministic sub-set of the source 161a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin List<Integer> expected = new ArrayList<>(); 162a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin data.forEach(expected::add); 163a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 164a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin List<T> actual = Arrays.asList(act); 165a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 166a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(actual.size(), exp.length); 167a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(expected.containsAll(actual)); 168a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin return; 169a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 170a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin else if (!ord) { 171a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.assertContentsUnordered(Arrays.asList(act), 172a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Arrays.asList(exp)); 173a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin return; 174a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 175a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 176a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(act, exp); 177a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin }; 178a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 179a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 180a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class, 181a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin groups = { "serialization-hostile" }) 182a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testStatefulOpPermutations(String name, TestData.OfRef<Integer> data) { 183a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<Stream<Integer>, Stream<Integer>> f : statefulOpPermutations) { 184a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin withData(data).terminal(f, s -> s.toArray()) 185a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .resultAsserter(statefulOpResultAsserter(data)) 186a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .exercise(); 187a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 188a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Integer[] is = withData(data).terminal(f, s -> s.toArray(Integer[]::new)) 189a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .resultAsserter(statefulOpResultAsserter(data)) 190a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .exercise(); 191a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(is.getClass(), Integer[].class); 192a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 193a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Number[] ns = withData(data).terminal(f, s -> s.toArray(Number[]::new)) 194a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .resultAsserter(statefulOpResultAsserter(data)) 195a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin .exercise(); 196a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(ns.getClass(), Number[].class); 197a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 198a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin if (data.size() > 0) { 199a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin Exception caught = null; 200a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin try { 201a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray(String[]::new)); 202a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } catch (Exception e) { 203a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin caught = e; 204a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 205a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(caught != null); 206a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertEquals(caught.getClass(), ArrayStoreException.class); 207a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 208a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 209a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 210a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 211a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // 212a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 213a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 214a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntOps(String name, TestData.OfInt data) { 215a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.toArray()); 216a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 217a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 218a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 219a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntOpsWithMap(String name, TestData.OfInt data) { 220a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 221a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 222a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 223a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin int[] ints = exerciseTerminalOps(data, s -> s.map(i -> i + i), s -> s.toArray()); 224a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(ints.length == data.size()); 225a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 226a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 227a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 228a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntOpsWithSorted(String name, TestData.OfInt data) { 229a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 230a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 231a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 232a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin int[] ints = exerciseTerminalOps(data, s -> s.sorted(), (IntStream s) -> s.toArray()); 233a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(ints.length == data.size()); 234a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 235a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 236a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 237a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntOpsWithFlatMap(String name, TestData.OfInt data) { 238a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Int the size of the source 239a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 240a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 241a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin int[] objects = exerciseTerminalOps(data, 242a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.flatMap(e -> Arrays.stream(new int[] { e, e })), 243a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.toArray()); 244a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size() * 2); 245a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 246a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 247a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 248a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntOpsWithFilter(String name, TestData.OfInt data) { 249a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Reduce the size of the source 250a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 251a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 252a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.filter(LambdaTestHelpers.ipEven), s -> s.toArray()); 253a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 254a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 255a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<IntStream, IntStream>> intUniqueAndSortedPermutations = 256a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 257a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 258a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 259a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted(), 260a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 261a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 262a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 263a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 264a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntDistinctAndSortedPermutations(String name, TestData.OfInt data) { 265a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<IntStream, IntStream> f : intUniqueAndSortedPermutations) { 266a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 267a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 268a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 269a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 270a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<IntStream, IntStream>> intStatefulOpPermutations = 271a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 272a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.limit(10), 273a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 274a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 275a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 276a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 277a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 278a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testIntStatefulOpPermutations(String name, TestData.OfInt data) { 279a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<IntStream, IntStream> f : intStatefulOpPermutations) { 280a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 281a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 282a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 283a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 284a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // 285a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 286a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 287a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongOps(String name, TestData.OfLong data) { 288a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.toArray()); 289a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 290a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 291a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 292a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongOpsWithMap(String name, TestData.OfLong data) { 293a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 294a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 295a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 296a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin long[] longs = exerciseTerminalOps(data, s -> s.map(i -> i + i), s -> s.toArray()); 297a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(longs.length == data.size()); 298a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 299a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 300a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 301a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongOpsWithSorted(String name, TestData.OfLong data) { 302a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 303a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 304a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 305a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin long[] longs = exerciseTerminalOps(data, s -> s.sorted(), (LongStream s) -> s.toArray()); 306a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(longs.length == data.size()); 307a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 308a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 309a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 310a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongOpsWithFlatMap(String name, TestData.OfLong data) { 311a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Long the size of the source 312a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 313a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 314a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin long[] objects = exerciseTerminalOps(data, 315a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.flatMap(e -> Arrays.stream(new long[] { e, e })), 316a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.toArray()); 317a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size() * 2); 318a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 319a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 320a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 321a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongOpsWithFilter(String name, TestData.OfLong data) { 322a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Reduce the size of the source 323a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 324a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 325a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.filter(LambdaTestHelpers.lpEven), s -> s.toArray()); 326a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 327a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 328a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<LongStream, LongStream>> longUniqueAndSortedPermutations = 329a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 330a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 331a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 332a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted(), 333a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 334a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 335a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 336a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 337a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongDistinctAndSortedPermutations(String name, TestData.OfLong data) { 338a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<LongStream, LongStream> f : longUniqueAndSortedPermutations) { 339a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 340a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 341a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 342a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 343a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<LongStream, LongStream>> longStatefulOpPermutations = 344a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 345a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.limit(10), 346a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 347a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 348a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 349a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 350a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 351a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testLongStatefulOpPermutations(String name, TestData.OfLong data) { 352a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<LongStream, LongStream> f : longStatefulOpPermutations) { 353a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 354a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 355a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 356a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 357a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // 358a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 359a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 360a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleOps(String name, TestData.OfDouble data) { 361a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.toArray()); 362a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 363a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 364a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 365a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleOpsWithMap(String name, TestData.OfDouble data) { 366a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 367a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 368a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 369a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin double[] doubles = exerciseTerminalOps(data, s -> s.map(i -> i + i), s -> s.toArray()); 370a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(doubles.length == data.size()); 371a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 372a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 373a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 374a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleOpsWithSorted(String name, TestData.OfDouble data) { 375a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Retain the size of the source 376a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // This should kick in the parallel evaluation optimization for tasks stuffing elements into a shared array 377a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 378a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin double[] doubles = exerciseTerminalOps(data, s -> s.sorted(), (DoubleStream s) -> s.toArray()); 379a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(doubles.length == data.size()); 380a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 381a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 382a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 383a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleOpsWithFlatMap(String name, TestData.OfDouble data) { 384a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Double the size of the source 385a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 386a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 387a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin double[] objects = exerciseTerminalOps(data, 388a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.flatMap(e -> Arrays.stream(new double[] { e, e })), 389a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.toArray()); 390a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin assertTrue(objects.length == data.size() * 2); 391a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 392a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 393a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 394a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleOpsWithFilter(String name, TestData.OfDouble data) { 395a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Reduce the size of the source 396a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin // Fixed size optimizations will not be used 397a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 398a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, s -> s.filter(LambdaTestHelpers.dpEven), s -> s.toArray()); 399a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 400a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 401a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<DoubleStream, DoubleStream>> doubleUniqueAndSortedPermutations = 402a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 403a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 404a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 405a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted(), 406a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 407a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 408a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 409a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 410a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleDistinctAndSortedPermutations(String name, TestData.OfDouble data) { 411a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<DoubleStream, DoubleStream> f : doubleUniqueAndSortedPermutations) { 412a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 413a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 414a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 415a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 416a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin private List<Function<DoubleStream, DoubleStream>> doubleStatefulOpPermutations = 417a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin LambdaTestHelpers.permuteStreamFunctions(Arrays.asList( 418a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.limit(10), 419a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.distinct(), 420a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin s -> s.sorted() 421a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin )); 422a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin 423a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 424a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin public void testDoubleStatefulOpPermutations(String name, TestData.OfDouble data) { 425a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin for (Function<DoubleStream, DoubleStream> f : doubleStatefulOpPermutations) { 426a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin exerciseTerminalOps(data, f, s -> s.toArray()); 427a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 428a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin } 429a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin} 430