1a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin/*
2a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Copyright (C) 2016 The Android Open Source Project
3a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
4a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin *
6a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * This code is free software; you can redistribute it and/or modify it
7a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * under the terms of the GNU General Public License version 2 only, as
8a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * published by the Free Software Foundation.
9a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin *
10a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * This code is distributed in the hope that it will be useful, but WITHOUT
11a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * version 2 for more details (a copy is included in the LICENSE file that
14a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * accompanied this code).
15a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin *
16a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * You should have received a copy of the GNU General Public License version
17a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * 2 along with this work; if not, write to the Free Software Foundation,
18a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin *
20a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * or visit www.oracle.com if you need additional information or have any
22a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin * questions.
23a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin */
24a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinpackage org.openjdk.tests.java.util.stream;
25a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
26a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport org.testng.annotations.DataProvider;
27a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport org.testng.annotations.Factory;
28a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport org.testng.annotations.Test;
29a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport org.testng.annotations.BeforeClass;
30a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
31a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.Arrays;
32a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.Collection;
33a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.Collections;
34a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.LinkedHashSet;
35a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.LinkedList;
36a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.List;
37a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.Spliterator;
38a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.TreeSet;
39a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.stream.DoubleStream;
40a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.stream.IntStream;
41a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.stream.LongStream;
42a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport java.util.stream.Stream;
43a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
44289e51c2258b001f2aa6d6e67b21be7bb65d5102Igor Murashkinimport static org.openjdk.testlib.java.util.stream.LambdaTestHelpers.*;
45a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinimport static org.testng.Assert.*;
46a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
47a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin@Test
48a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkinpublic class ConcatTest {
49a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private static Object[][] cases;
50a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
51a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    static {
52a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        List<Integer> part1 = Arrays.asList(5, 3, 4, 1, 2, 6, 2, 4);
53a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        List<Integer> part2 = Arrays.asList(8, 8, 6, 6, 9, 7, 10, 9);
54a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        List<Integer> p1p2 = Arrays.asList(5, 3, 4, 1, 2, 6, 2, 4, 8, 8, 6, 6, 9, 7, 10, 9);
55a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        List<Integer> p2p1 = Arrays.asList(8, 8, 6, 6, 9, 7, 10, 9, 5, 3, 4, 1, 2, 6, 2, 4);
56a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        List<Integer> empty = new LinkedList<>(); // To be ordered
57a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(empty.isEmpty());
58a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        LinkedHashSet<Integer> distinctP1 = new LinkedHashSet<>(part1);
59a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        LinkedHashSet<Integer> distinctP2 = new LinkedHashSet<>(part2);
60a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        TreeSet<Integer> sortedP1 = new TreeSet<>(part1);
61a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        TreeSet<Integer> sortedP2 = new TreeSet<>(part2);
62a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
63a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        cases = new Object[][] {
64a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "regular", part1, part2, p1p2 },
65a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "reverse regular", part2, part1, p2p1 },
66a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "front distinct", distinctP1, part2, Arrays.asList(5, 3, 4, 1, 2, 6, 8, 8, 6, 6, 9, 7, 10, 9) },
67a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "back distinct", part1, distinctP2, Arrays.asList(5, 3, 4, 1, 2, 6, 2, 4, 8, 6, 9, 7, 10) },
68a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "both distinct", distinctP1, distinctP2, Arrays.asList(5, 3, 4, 1, 2, 6, 8, 6, 9, 7, 10) },
69a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "front sorted", sortedP1, part2, Arrays.asList(1, 2, 3, 4, 5, 6, 8, 8, 6, 6, 9, 7, 10, 9) },
70a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "back sorted", part1, sortedP2, Arrays.asList(5, 3, 4, 1, 2, 6, 2, 4, 6, 7, 8, 9, 10) },
71a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "both sorted", sortedP1, sortedP2, Arrays.asList(1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10) },
72a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "reverse both sorted", sortedP2, sortedP1, Arrays.asList(6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6) },
73a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "empty something", empty, part1, part1 },
74a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "something empty", part1, empty, part1 },
75a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            { "empty empty", empty, empty, empty }
76a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        };
77a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
78a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
79a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    @DataProvider(name = "cases")
80a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private static Object[][] getCases() {
81a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        return cases;
82a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
83a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
84a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    @Factory(dataProvider = "cases")
85a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public static Object[] createTests(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
86a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        return new Object[] {
87a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            new ConcatTest(scenario, c1, c2, expected)
88a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        };
89a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
90a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
91a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    protected final String scenario;
92a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    protected final Collection<Integer> c1;
93a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    protected final Collection<Integer> c2;
94a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    protected final Collection<Integer> expected;
95a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
96a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public ConcatTest(String scenario, Collection<Integer> c1, Collection<Integer> c2, Collection<Integer> expected) {
97a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        this.scenario = scenario;
98a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        this.c1 = c1;
99a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        this.c2 = c2;
100a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        this.expected = expected;
101a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
102a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
103a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    // Android-changed: Factor out the prerequisites check out of the constructor.
104a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    // TestNG crashes hard if an assert is thrown in the constructor.
105a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    // This is done for test readability only and doesn't impact test logic.
106a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    @BeforeClass
107a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public void checkPrerequisites() {
108a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // verify prerequisite
109a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        Stream<Integer> s1s = c1.stream();
110a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        Stream<Integer> s2s = c2.stream();
111a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        Stream<Integer> s1p = c1.parallelStream();
112a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        Stream<Integer> s2p = c2.parallelStream();
113a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s1p.isParallel());
114a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s2p.isParallel());
115a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertFalse(s1s.isParallel());
116a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertFalse(s2s.isParallel());
117a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
118a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // Android-changed: Also add the class name to easier debug. Doesn't impact logic.
119a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s1s.spliterator().hasCharacteristics(Spliterator.ORDERED), c1.getClass().toString());
120a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s1p.spliterator().hasCharacteristics(Spliterator.ORDERED), c2.getClass().toString());
121a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s2s.spliterator().hasCharacteristics(Spliterator.ORDERED), c1.getClass().toString());
122a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertTrue(s2p.spliterator().hasCharacteristics(Spliterator.ORDERED), c2.getClass().toString());
123a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
124a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
125a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private <T> void assertConcatContent(Spliterator<T> sp, boolean ordered, Spliterator<T> expected) {
126a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // concat stream cannot guarantee uniqueness
127a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertFalse(sp.hasCharacteristics(Spliterator.DISTINCT), scenario);
128a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // concat stream cannot guarantee sorted
129a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertFalse(sp.hasCharacteristics(Spliterator.SORTED), scenario);
130a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // concat stream is ordered if both are ordered
131a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertEquals(sp.hasCharacteristics(Spliterator.ORDERED), ordered, scenario);
132a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
133a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // Verify elements
134a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        if (ordered) {
135a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            assertEquals(toBoxedList(sp),
136a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                         toBoxedList(expected),
137a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                         scenario);
138a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        } else {
139a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin            assertEquals(toBoxedMultiset(sp),
140a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                         toBoxedMultiset(expected),
141a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                         scenario);
142a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        }
143a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
144a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
145a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private void assertRefConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
146a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        Stream<Integer> result = Stream.concat(s1, s2);
147a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertEquals(result.isParallel(), parallel);
148a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertConcatContent(result.spliterator(), ordered, expected.spliterator());
149a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
150a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
151a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private void assertIntConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
152a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        IntStream result = IntStream.concat(s1.mapToInt(Integer::intValue),
153a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                                            s2.mapToInt(Integer::intValue));
154a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertEquals(result.isParallel(), parallel);
155a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertConcatContent(result.spliterator(), ordered,
156a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                            expected.stream().mapToInt(Integer::intValue).spliterator());
157a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
158a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
159a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private void assertLongConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
160a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        LongStream result = LongStream.concat(s1.mapToLong(Integer::longValue),
161a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                                              s2.mapToLong(Integer::longValue));
162a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertEquals(result.isParallel(), parallel);
163a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertConcatContent(result.spliterator(), ordered,
164a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                            expected.stream().mapToLong(Integer::longValue).spliterator());
165a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
166a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
167a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    private void assertDoubleConcat(Stream<Integer> s1, Stream<Integer> s2, boolean parallel, boolean ordered) {
168a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        DoubleStream result = DoubleStream.concat(s1.mapToDouble(Integer::doubleValue),
169a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                                                  s2.mapToDouble(Integer::doubleValue));
170a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertEquals(result.isParallel(), parallel);
171a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertConcatContent(result.spliterator(), ordered,
172a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin                            expected.stream().mapToDouble(Integer::doubleValue).spliterator());
173a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
174a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
175a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public void testRefConcat() {
176a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + sequential -> sequential
177a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.stream(), c2.stream(), false, true);
178a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + parallel -> parallel
179a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.parallelStream(), c2.parallelStream(), true, true);
180a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + parallel -> parallel
181a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.stream(), c2.parallelStream(), true, true);
182a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + sequential -> parallel
183a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.parallelStream(), c2.stream(), true, true);
184a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
185a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // not ordered
186a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.stream().unordered(), c2.stream(), false, false);
187a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.stream(), c2.stream().unordered(), false, false);
188a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertRefConcat(c1.parallelStream().unordered(), c2.stream().unordered(), true, false);
189a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
190a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
191a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public void testIntConcat() {
192a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + sequential -> sequential
193a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.stream(), c2.stream(), false, true);
194a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + parallel -> parallel
195a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.parallelStream(), c2.parallelStream(), true, true);
196a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + parallel -> parallel
197a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.stream(), c2.parallelStream(), true, true);
198a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + sequential -> parallel
199a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.parallelStream(), c2.stream(), true, true);
200a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
201a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // not ordered
202a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.stream().unordered(), c2.stream(), false, false);
203a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.stream(), c2.stream().unordered(), false, false);
204a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertIntConcat(c1.parallelStream().unordered(), c2.stream().unordered(), true, false);
205a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
206a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
207a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public void testLongConcat() {
208a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + sequential -> sequential
209a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.stream(), c2.stream(), false, true);
210a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + parallel -> parallel
211a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.parallelStream(), c2.parallelStream(), true, true);
212a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + parallel -> parallel
213a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.stream(), c2.parallelStream(), true, true);
214a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + sequential -> parallel
215a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.parallelStream(), c2.stream(), true, true);
216a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
217a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // not ordered
218a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.stream().unordered(), c2.stream(), false, false);
219a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.stream(), c2.stream().unordered(), false, false);
220a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertLongConcat(c1.parallelStream().unordered(), c2.stream().unordered(), true, false);
221a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
222a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
223a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    public void testDoubleConcat() {
224a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + sequential -> sequential
225a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.stream(), c2.stream(), false, true);
226a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + parallel -> parallel
227a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.parallelStream(), c2.parallelStream(), true, true);
228a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // sequential + parallel -> parallel
229a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.stream(), c2.parallelStream(), true, true);
230a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // parallel + sequential -> parallel
231a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.parallelStream(), c2.stream(), true, true);
232a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin
233a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        // not ordered
234a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.stream().unordered(), c2.stream(), false, false);
235a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.stream(), c2.stream().unordered(), false, false);
236a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin        assertDoubleConcat(c1.parallelStream().unordered(), c2.stream().unordered(), true, false);
237a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin    }
238a405b7ea164e472bcf6b75d9890021bd82e4d60dIgor Murashkin}
239