undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
4
test/jdk/java/util/stream/boottest/TEST.properties
Normal file
4
test/jdk/java/util/stream/boottest/TEST.properties
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# This file identifies root(s) of the test-ng hierarchy.
|
||||
|
||||
TestNG.dirs = .
|
||||
lib.dirs = /lib/testlibrary/bootlib
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractSpinedBufferTest {
|
||||
|
||||
// Create sizes around the boundary of spines
|
||||
static final List<Integer> SIZES;
|
||||
static {
|
||||
try {
|
||||
SIZES = IntStream.range(0, 15)
|
||||
.map(i -> 1 << i)
|
||||
.flatMap(i -> Arrays.stream(new int[] { i-2, i-1, i, i+1, i+2 }))
|
||||
.filter(i -> i >= 0)
|
||||
.boxed()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static final int TEST_SIZE = 5000;
|
||||
}
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.SpliteratorTestHelper;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class DoubleNodeTest extends OpTestCase {
|
||||
|
||||
@DataProvider(name = "nodes")
|
||||
public Object[][] createSizes() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : Arrays.asList(0, 1, 4, 15, 16, 17, 127, 128, 129, 1000)) {
|
||||
double[] array = new double[size];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i;
|
||||
}
|
||||
|
||||
List<Node<Double>> nodes = new ArrayList<>();
|
||||
|
||||
nodes.add(Nodes.node(array));
|
||||
nodes.add(degenerateTree(Spliterators.iterator(Arrays.spliterator(array))));
|
||||
nodes.add(tree(toList(array), l -> Nodes.node(toDoubleArray(l))));
|
||||
nodes.add(fill(array, Nodes.doubleBuilder(array.length)));
|
||||
nodes.add(fill(array, Nodes.doubleBuilder()));
|
||||
|
||||
for (Node<Double> node : nodes) {
|
||||
params.add(new Object[]{array, node});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
private static void assertEqualsListDoubleArray(List<Double> list, double[] array) {
|
||||
assertEquals(list.size(), array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
assertEquals(array[i], (double) list.get(i));
|
||||
}
|
||||
|
||||
private List<Double> toList(double[] a) {
|
||||
List<Double> l = new ArrayList<>();
|
||||
for (double i : a) {
|
||||
l.add(i);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
private double[] toDoubleArray(List<Double> l) {
|
||||
double[] a = new double[l.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Double e : l) {
|
||||
a[i++] = e;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private Node.OfDouble fill(double[] array, Node.Builder.OfDouble nb) {
|
||||
nb.begin(array.length);
|
||||
for (double i : array)
|
||||
nb.accept(i);
|
||||
nb.end();
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
private Node.OfDouble degenerateTree(PrimitiveIterator.OfDouble it) {
|
||||
if (!it.hasNext()) {
|
||||
return Nodes.node(new double[0]);
|
||||
}
|
||||
|
||||
double i = it.nextDouble();
|
||||
if (it.hasNext()) {
|
||||
return new Nodes.ConcNode.OfDouble(Nodes.node(new double[] {i}), degenerateTree(it));
|
||||
}
|
||||
else {
|
||||
return Nodes.node(new double[] {i});
|
||||
}
|
||||
}
|
||||
|
||||
private Node.OfDouble tree(List<Double> l, Function<List<Double>, Node.OfDouble> m) {
|
||||
if (l.size() < 3) {
|
||||
return m.apply(l);
|
||||
}
|
||||
else {
|
||||
return new Nodes.ConcNode.OfDouble(
|
||||
tree(l.subList(0, l.size() / 2), m),
|
||||
tree(l.subList(l.size() / 2, l.size()), m));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testAsArray(double[] array, Node.OfDouble n) {
|
||||
assertEquals(n.asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testFlattenAsArray(double[] array, Node.OfDouble n) {
|
||||
assertEquals(Nodes.flattenDouble(n).asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testCopyTo(double[] array, Node.OfDouble n) {
|
||||
double[] copy = new double[(int) n.count()];
|
||||
n.copyInto(copy, 0);
|
||||
|
||||
assertEquals(copy, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes", groups = { "serialization-hostile" })
|
||||
public void testForEach(double[] array, Node.OfDouble n) {
|
||||
List<Double> l = new ArrayList<>((int) n.count());
|
||||
n.forEach((double e) -> {
|
||||
l.add(e);
|
||||
});
|
||||
|
||||
assertEqualsListDoubleArray(l, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testStreams(double[] array, Node.OfDouble n) {
|
||||
TestData.OfDouble data = TestData.Factory.ofNode("Node", n);
|
||||
|
||||
exerciseOps(data, s -> s);
|
||||
|
||||
exerciseTerminalOps(data, s -> s.toArray());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes", groups={ "serialization-hostile" })
|
||||
// throws SOE on serialization of DoubleConcNode[size=1000]
|
||||
public void testSpliterator(double[] array, Node.OfDouble n) {
|
||||
SpliteratorTestHelper.testDoubleSpliterator(n::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testTruncate(double[] array, Node.OfDouble n) {
|
||||
int[] nums = new int[] { 0, 1, array.length / 2, array.length - 1, array.length };
|
||||
for (int start : nums)
|
||||
for (int end : nums) {
|
||||
if (start < 0 || end < 0 || end < start || end > array.length)
|
||||
continue;
|
||||
Node.OfDouble slice = n.truncate(start, end, Double[]::new);
|
||||
double[] asArray = slice.asPrimitiveArray();
|
||||
for (int k = start; k < end; k++)
|
||||
assertEquals(array[k], asArray[k - start]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.stream.LambdaTestHelpers.countTo;
|
||||
|
||||
@Test
|
||||
public class FlagOpTest extends OpTestCase {
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testFlagsPassThrough(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
TestFlagPassThroughOp<Integer>[] ops = new TestFlagPassThroughOp[3];
|
||||
ops[0] = new TestFlagPassThroughOp<>();
|
||||
ops[1] = new TestFlagPassThroughOp<>();
|
||||
ops[2] = new TestFlagPassThroughOp<>();
|
||||
|
||||
ops[0].set(null, ops[1]);
|
||||
ops[1].set(ops[0], ops[2]);
|
||||
ops[2].set(ops[1], null);
|
||||
|
||||
withData(data).ops(ops).exercise();
|
||||
}
|
||||
|
||||
static class TestFlagPassThroughOp<T> extends FlagDeclaringOp<T> {
|
||||
TestFlagPassThroughOp<T> upstream;
|
||||
TestFlagPassThroughOp<T> downstream;
|
||||
|
||||
TestFlagPassThroughOp() {
|
||||
super(0);
|
||||
}
|
||||
|
||||
void set(TestFlagPassThroughOp<T> upstream, TestFlagPassThroughOp<T> downstream) {
|
||||
this.upstream = upstream;
|
||||
this.downstream = downstream;
|
||||
}
|
||||
|
||||
int wrapFlags;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Sink<T> opWrapSink(int flags, boolean parallel, Sink sink) {
|
||||
this.wrapFlags = flags;
|
||||
|
||||
if (downstream != null) {
|
||||
assertTrue(flags == downstream.wrapFlags);
|
||||
}
|
||||
|
||||
return sink;
|
||||
}
|
||||
}
|
||||
|
||||
public void testFlagsClearAllSet() {
|
||||
int clearAllFlags = 0;
|
||||
for (StreamOpFlag f : EnumSet.allOf(StreamOpFlag.class)) {
|
||||
if (f.isStreamFlag()) {
|
||||
clearAllFlags |= f.clear();
|
||||
}
|
||||
}
|
||||
|
||||
EnumSet<StreamOpFlag> known = EnumSet.noneOf(StreamOpFlag.class);
|
||||
EnumSet<StreamOpFlag> notKnown = StreamOpFlagTestHelper.allStreamFlags();
|
||||
|
||||
List<FlagDeclaringOp<Integer>> ops = new ArrayList<>();
|
||||
ops.add(new FlagDeclaringOp<>(clearAllFlags));
|
||||
for (StreamOpFlag f : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
if (f.canSet(StreamOpFlag.Type.OP)) {
|
||||
ops.add(new TestFlagExpectedOp<>(f.set(),
|
||||
known.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class),
|
||||
notKnown.clone()));
|
||||
known.add(f);
|
||||
notKnown.remove(f);
|
||||
}
|
||||
}
|
||||
ops.add(new TestFlagExpectedOp<>(0,
|
||||
known.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class),
|
||||
notKnown.clone()));
|
||||
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
FlagDeclaringOp[] opsArray = ops.toArray(new FlagDeclaringOp[ops.size()]);
|
||||
|
||||
withData(data).ops(opsArray).
|
||||
without(StreamTestScenario.CLEAR_SIZED_SCENARIOS).
|
||||
exercise();
|
||||
}
|
||||
|
||||
public void testFlagsSetAllClear() {
|
||||
EnumSet<StreamOpFlag> known = StreamOpFlagTestHelper.allStreamFlags();
|
||||
int setAllFlags = 0;
|
||||
for (StreamOpFlag f : EnumSet.allOf(StreamOpFlag.class)) {
|
||||
if (f.isStreamFlag()) {
|
||||
if (f.canSet(StreamOpFlag.Type.OP)) {
|
||||
setAllFlags |= f.set();
|
||||
} else {
|
||||
known.remove(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnumSet<StreamOpFlag> notKnown = EnumSet.noneOf(StreamOpFlag.class);
|
||||
|
||||
List<FlagDeclaringOp<Integer>> ops = new ArrayList<>();
|
||||
ops.add(new FlagDeclaringOp<>(setAllFlags));
|
||||
for (StreamOpFlag f : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
ops.add(new TestFlagExpectedOp<>(f.clear(),
|
||||
known.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class),
|
||||
notKnown.clone()));
|
||||
known.remove(f);
|
||||
notKnown.add(f);
|
||||
}
|
||||
ops.add(new TestFlagExpectedOp<>(0,
|
||||
known.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class),
|
||||
notKnown.clone()));
|
||||
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
FlagDeclaringOp[] opsArray = ops.toArray(new FlagDeclaringOp[ops.size()]);
|
||||
|
||||
|
||||
withData(data).ops(opsArray).
|
||||
without(StreamTestScenario.CLEAR_SIZED_SCENARIOS).
|
||||
exercise();
|
||||
}
|
||||
|
||||
public void testFlagsParallelCollect() {
|
||||
testFlagsSetSequence(CollectorOps::collector);
|
||||
}
|
||||
|
||||
private void testFlagsSetSequence(Supplier<StatefulTestOp<Integer>> cf) {
|
||||
EnumSet<StreamOpFlag> known = EnumSet.of(StreamOpFlag.ORDERED, StreamOpFlag.SIZED);
|
||||
EnumSet<StreamOpFlag> preserve = EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED);
|
||||
|
||||
List<IntermediateTestOp<Integer, Integer>> ops = new ArrayList<>();
|
||||
for (StreamOpFlag f : EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED)) {
|
||||
ops.add(cf.get());
|
||||
ops.add(new TestFlagExpectedOp<>(f.set(),
|
||||
known.clone(),
|
||||
preserve.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class)));
|
||||
known.add(f);
|
||||
preserve.remove(f);
|
||||
}
|
||||
ops.add(cf.get());
|
||||
ops.add(new TestFlagExpectedOp<>(0,
|
||||
known.clone(),
|
||||
preserve.clone(),
|
||||
EnumSet.noneOf(StreamOpFlag.class)));
|
||||
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
IntermediateTestOp[] opsArray = ops.toArray(new IntermediateTestOp[ops.size()]);
|
||||
|
||||
withData(data).ops(opsArray).
|
||||
without(StreamTestScenario.CLEAR_SIZED_SCENARIOS).
|
||||
exercise();
|
||||
}
|
||||
|
||||
|
||||
public void testFlagsClearParallelCollect() {
|
||||
testFlagsClearSequence(CollectorOps::collector);
|
||||
}
|
||||
|
||||
protected void testFlagsClearSequence(Supplier<StatefulTestOp<Integer>> cf) {
|
||||
EnumSet<StreamOpFlag> known = EnumSet.of(StreamOpFlag.ORDERED, StreamOpFlag.SIZED);
|
||||
EnumSet<StreamOpFlag> preserve = EnumSet.of(StreamOpFlag.DISTINCT, StreamOpFlag.SORTED);
|
||||
EnumSet<StreamOpFlag> notKnown = EnumSet.noneOf(StreamOpFlag.class);
|
||||
|
||||
List<IntermediateTestOp<Integer, Integer>> ops = new ArrayList<>();
|
||||
for (StreamOpFlag f : EnumSet.of(StreamOpFlag.ORDERED, StreamOpFlag.DISTINCT, StreamOpFlag.SORTED)) {
|
||||
ops.add(cf.get());
|
||||
ops.add(new TestFlagExpectedOp<>(f.clear(),
|
||||
known.clone(),
|
||||
preserve.clone(),
|
||||
notKnown.clone()));
|
||||
known.remove(f);
|
||||
preserve.remove(f);
|
||||
notKnown.add(f);
|
||||
}
|
||||
ops.add(cf.get());
|
||||
ops.add(new TestFlagExpectedOp<>(0,
|
||||
known.clone(),
|
||||
preserve.clone(),
|
||||
notKnown.clone()));
|
||||
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
IntermediateTestOp[] opsArray = ops.toArray(new IntermediateTestOp[ops.size()]);
|
||||
|
||||
withData(data).ops(opsArray).
|
||||
without(StreamTestScenario.CLEAR_SIZED_SCENARIOS).
|
||||
exercise();
|
||||
}
|
||||
|
||||
public void testFlagsSizedOrderedParallelCollect() {
|
||||
EnumSet<StreamOpFlag> parKnown = EnumSet.of(StreamOpFlag.SIZED);
|
||||
EnumSet<StreamOpFlag> serKnown = parKnown.clone();
|
||||
|
||||
List<IntermediateTestOp<Integer, Integer>> ops = new ArrayList<>();
|
||||
for (StreamOpFlag f : parKnown) {
|
||||
ops.add(CollectorOps.collector());
|
||||
ops.add(new ParSerTestFlagExpectedOp<>(f.clear(),
|
||||
parKnown,
|
||||
serKnown));
|
||||
serKnown.remove(f);
|
||||
}
|
||||
ops.add(CollectorOps.collector());
|
||||
ops.add(new ParSerTestFlagExpectedOp<>(0,
|
||||
parKnown,
|
||||
EnumSet.noneOf(StreamOpFlag.class)));
|
||||
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofArray("Array", countTo(10).toArray(new Integer[0]));
|
||||
@SuppressWarnings("rawtypes")
|
||||
IntermediateTestOp[] opsArray = ops.toArray(new IntermediateTestOp[ops.size()]);
|
||||
|
||||
withData(data).ops(opsArray).exercise();
|
||||
}
|
||||
|
||||
static class ParSerTestFlagExpectedOp<T> extends FlagDeclaringOp<T> {
|
||||
final EnumSet<StreamOpFlag> parKnown;
|
||||
final EnumSet<StreamOpFlag> serKnown;
|
||||
|
||||
ParSerTestFlagExpectedOp(int flags, EnumSet<StreamOpFlag> known, EnumSet<StreamOpFlag> serKnown) {
|
||||
super(flags);
|
||||
this.parKnown = known;
|
||||
this.serKnown = serKnown;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Sink<T> opWrapSink(int flags, boolean parallel, Sink upstream) {
|
||||
assertFlags(flags, parallel);
|
||||
return upstream;
|
||||
}
|
||||
|
||||
protected void assertFlags(int flags, boolean parallel) {
|
||||
if (parallel) {
|
||||
for (StreamOpFlag f : parKnown) {
|
||||
Assert.assertTrue(f.isKnown(flags), String.format("Flag %s is not known, but should be known.", f.toString()));
|
||||
}
|
||||
|
||||
} else {
|
||||
for (StreamOpFlag f : serKnown) {
|
||||
Assert.assertTrue(f.isKnown(flags), String.format("Flag %s is not known, but should be known.", f.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.SpliteratorTestHelper;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class IntNodeTest extends OpTestCase {
|
||||
|
||||
@DataProvider(name = "nodes")
|
||||
public Object[][] createSizes() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : Arrays.asList(0, 1, 4, 15, 16, 17, 127, 128, 129, 1000)) {
|
||||
int[] array = new int[size];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i;
|
||||
}
|
||||
|
||||
List<Node<Integer>> nodes = new ArrayList<>();
|
||||
|
||||
nodes.add(Nodes.node(array));
|
||||
nodes.add(degenerateTree(Spliterators.iterator(Arrays.spliterator(array))));
|
||||
nodes.add(tree(toList(array), l -> Nodes.node(toIntArray(l))));
|
||||
nodes.add(fill(array, Nodes.intBuilder(array.length)));
|
||||
nodes.add(fill(array, Nodes.intBuilder()));
|
||||
|
||||
for (Node<Integer> node : nodes) {
|
||||
params.add(new Object[]{array, node});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
private static void assertEqualsListIntArray(List<Integer> list, int[] array) {
|
||||
assertEquals(list.size(), array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
assertEquals(array[i], (int) list.get(i));
|
||||
}
|
||||
|
||||
private List<Integer> toList(int[] a) {
|
||||
List<Integer> l = new ArrayList<>();
|
||||
for (int i : a) {
|
||||
l.add(i);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
private int[] toIntArray(List<Integer> l) {
|
||||
int[] a = new int[l.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Integer e : l) {
|
||||
a[i++] = e;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private Node.OfInt fill(int[] array, Node.Builder.OfInt nb) {
|
||||
nb.begin(array.length);
|
||||
for (int i : array)
|
||||
nb.accept(i);
|
||||
nb.end();
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
private Node.OfInt degenerateTree(PrimitiveIterator.OfInt it) {
|
||||
if (!it.hasNext()) {
|
||||
return Nodes.node(new int[0]);
|
||||
}
|
||||
|
||||
int i = it.nextInt();
|
||||
if (it.hasNext()) {
|
||||
return new Nodes.ConcNode.OfInt(Nodes.node(new int[] {i}), degenerateTree(it));
|
||||
}
|
||||
else {
|
||||
return Nodes.node(new int[] {i});
|
||||
}
|
||||
}
|
||||
|
||||
private Node.OfInt tree(List<Integer> l, Function<List<Integer>, Node.OfInt> m) {
|
||||
if (l.size() < 3) {
|
||||
return m.apply(l);
|
||||
}
|
||||
else {
|
||||
return new Nodes.ConcNode.OfInt(
|
||||
tree(l.subList(0, l.size() / 2), m),
|
||||
tree(l.subList(l.size() / 2, l.size()), m));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testAsArray(int[] array, Node.OfInt n) {
|
||||
assertEquals(n.asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testFlattenAsArray(int[] array, Node.OfInt n) {
|
||||
assertEquals(Nodes.flattenInt(n).asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testCopyTo(int[] array, Node.OfInt n) {
|
||||
int[] copy = new int[(int) n.count()];
|
||||
n.copyInto(copy, 0);
|
||||
|
||||
assertEquals(copy, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes", groups = { "serialization-hostile" })
|
||||
public void testForEach(int[] array, Node.OfInt n) {
|
||||
List<Integer> l = new ArrayList<>((int) n.count());
|
||||
n.forEach((int e) -> {
|
||||
l.add(e);
|
||||
});
|
||||
|
||||
assertEqualsListIntArray(l, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testStreams(int[] array, Node.OfInt n) {
|
||||
TestData.OfInt data = TestData.Factory.ofNode("Node", n);
|
||||
|
||||
exerciseOps(data, s -> s);
|
||||
exerciseTerminalOps(data, s -> s.toArray());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testSpliterator(int[] array, Node.OfInt n) {
|
||||
SpliteratorTestHelper.testIntSpliterator(n::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testTruncate(int[] array, Node.OfInt n) {
|
||||
int[] nums = new int[] { 0, 1, array.length / 2, array.length - 1, array.length };
|
||||
for (int start : nums)
|
||||
for (int end : nums) {
|
||||
if (start < 0 || end < 0 || end < start || end > array.length)
|
||||
continue;
|
||||
Node.OfInt slice = n.truncate(start, end, Integer[]::new);
|
||||
int[] asArray = slice.asPrimitiveArray();
|
||||
for (int k = start; k < end; k++)
|
||||
assertEquals(array[k], asArray[k - start]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.SpliteratorTestHelper;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class LongNodeTest extends OpTestCase {
|
||||
|
||||
@DataProvider(name = "nodes")
|
||||
public Object[][] createSizes() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : Arrays.asList(0, 1, 4, 15, 16, 17, 127, 128, 129, 1000)) {
|
||||
long[] array = new long[size];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i;
|
||||
}
|
||||
|
||||
List<Node<Long>> nodes = new ArrayList<>();
|
||||
|
||||
nodes.add(Nodes.node(array));
|
||||
nodes.add(degenerateTree(Spliterators.iterator(Arrays.spliterator(array))));
|
||||
nodes.add(tree(toList(array), l -> Nodes.node(toLongArray(l))));
|
||||
nodes.add(fill(array, Nodes.longBuilder(array.length)));
|
||||
nodes.add(fill(array, Nodes.longBuilder()));
|
||||
|
||||
for (Node<Long> node : nodes) {
|
||||
params.add(new Object[]{array, node});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
private static void assertEqualsListLongArray(List<Long> list, long[] array) {
|
||||
assertEquals(list.size(), array.length);
|
||||
for (int i = 0; i < array.length; i++)
|
||||
assertEquals(array[i], (long) list.get(i));
|
||||
}
|
||||
|
||||
private List<Long> toList(long[] a) {
|
||||
List<Long> l = new ArrayList<>();
|
||||
for (long i : a) {
|
||||
l.add(i);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
private long[] toLongArray(List<Long> l) {
|
||||
long[] a = new long[l.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Long e : l) {
|
||||
a[i++] = e;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private Node.OfLong fill(long[] array, Node.Builder.OfLong nb) {
|
||||
nb.begin(array.length);
|
||||
for (long i : array)
|
||||
nb.accept(i);
|
||||
nb.end();
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
private Node.OfLong degenerateTree(PrimitiveIterator.OfLong it) {
|
||||
if (!it.hasNext()) {
|
||||
return Nodes.node(new long[0]);
|
||||
}
|
||||
|
||||
long i = it.nextLong();
|
||||
if (it.hasNext()) {
|
||||
return new Nodes.ConcNode.OfLong(Nodes.node(new long[] {i}), degenerateTree(it));
|
||||
}
|
||||
else {
|
||||
return Nodes.node(new long[] {i});
|
||||
}
|
||||
}
|
||||
|
||||
private Node.OfLong tree(List<Long> l, Function<List<Long>, Node.OfLong> m) {
|
||||
if (l.size() < 3) {
|
||||
return m.apply(l);
|
||||
}
|
||||
else {
|
||||
return new Nodes.ConcNode.OfLong(
|
||||
tree(l.subList(0, l.size() / 2), m),
|
||||
tree(l.subList(l.size() / 2, l.size()), m));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testAsArray(long[] array, Node.OfLong n) {
|
||||
assertEquals(n.asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testFlattenAsArray(long[] array, Node.OfLong n) {
|
||||
assertEquals(Nodes.flattenLong(n).asPrimitiveArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testCopyTo(long[] array, Node.OfLong n) {
|
||||
long[] copy = new long[(int) n.count()];
|
||||
n.copyInto(copy, 0);
|
||||
|
||||
assertEquals(copy, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes", groups = { "serialization-hostile" })
|
||||
public void testForEach(long[] array, Node.OfLong n) {
|
||||
List<Long> l = new ArrayList<>((int) n.count());
|
||||
n.forEach((long e) -> {
|
||||
l.add(e);
|
||||
});
|
||||
|
||||
assertEqualsListLongArray(l, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testStreams(long[] array, Node.OfLong n) {
|
||||
TestData.OfLong data = TestData.Factory.ofNode("Node", n);
|
||||
|
||||
exerciseOps(data, s -> s);
|
||||
|
||||
exerciseTerminalOps(data, s -> s.toArray());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testSpliterator(long[] array, Node.OfLong n) {
|
||||
SpliteratorTestHelper.testLongSpliterator(n::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testTruncate(long[] array, Node.OfLong n) {
|
||||
int[] nums = new int[] { 0, 1, array.length / 2, array.length - 1, array.length };
|
||||
for (int start : nums)
|
||||
for (int end : nums) {
|
||||
if (start < 0 || end < 0 || end < start || end > array.length)
|
||||
continue;
|
||||
Node.OfLong slice = n.truncate(start, end, Long[]::new);
|
||||
long[] asArray = slice.asPrimitiveArray();
|
||||
for (int k = start; k < end; k++)
|
||||
assertEquals(array[k], asArray[k - start]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.LongConsumer;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static java.util.stream.LambdaTestHelpers.assertContents;
|
||||
import static java.util.stream.LambdaTestHelpers.countTo;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
@Test
|
||||
public class NodeBuilderTest {
|
||||
|
||||
List<Integer> sizes = Arrays.asList(0, 1, 4, 16, 256,
|
||||
1023, 1024, 1025,
|
||||
2047, 2048, 2049,
|
||||
1024 * 32 - 1, 1024 * 32, 1024 * 32 + 1);
|
||||
|
||||
@DataProvider(name = "Node.Builder")
|
||||
public Object[][] createNodeBuilders() {
|
||||
List<List<Integer>> ls = new ArrayList<>();
|
||||
for (int size : sizes) {
|
||||
ls.add(countTo(size));
|
||||
}
|
||||
|
||||
List<Function<Integer, Node.Builder<Integer>>> ms = Arrays.asList(
|
||||
s -> Nodes.builder(),
|
||||
s -> Nodes.builder(s, LambdaTestHelpers.integerArrayGenerator)
|
||||
);
|
||||
|
||||
Object[][] params = new Object[ls.size() * ms.size()][];
|
||||
int i = 0;
|
||||
for (List<Integer> l : ls) {
|
||||
for (Function<Integer, Node.Builder<Integer>> m : ms) {
|
||||
params[i++] = new Object[]{l, m};
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "Node.Builder", groups = { "serialization-hostile" })
|
||||
public void testIteration(List<Integer> l, Function<Integer, Node.Builder<Integer>> m) {
|
||||
Node.Builder<Integer> nb = m.apply(l.size());
|
||||
nb.begin(l.size());
|
||||
for (Integer i : l) {
|
||||
nb.accept(i);
|
||||
}
|
||||
nb.end();
|
||||
|
||||
Node<Integer> n = nb.build();
|
||||
assertEquals(n.count(), l.size());
|
||||
|
||||
{
|
||||
List<Integer> _l = new ArrayList<>();
|
||||
n.forEach(_l::add);
|
||||
|
||||
assertContents(_l, l);
|
||||
}
|
||||
}
|
||||
|
||||
// Node.Builder.OfInt
|
||||
|
||||
@DataProvider(name = "Node.Builder<Integer>")
|
||||
public Object[][] createIntNodeBuilders() {
|
||||
List<List<Integer>> ls = new ArrayList<>();
|
||||
for (int size : sizes) {
|
||||
ls.add(countTo(size));
|
||||
}
|
||||
|
||||
List<Function<Integer, Node.Builder<Integer>>> ms = Arrays.asList(
|
||||
s -> Nodes.intBuilder(),
|
||||
s -> Nodes.intBuilder(s)
|
||||
);
|
||||
|
||||
Object[][] params = new Object[ls.size() * ms.size()][];
|
||||
int i = 0;
|
||||
for (List<Integer> l : ls) {
|
||||
for (Function<Integer, Node.Builder<Integer>> m : ms) {
|
||||
params[i++] = new Object[]{l, m};
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "Node.Builder<Integer>", groups = { "serialization-hostile" })
|
||||
public void testIntIteration(List<Integer> l, Function<Integer, Node.Builder.OfInt> m) {
|
||||
Node.Builder.OfInt nb = m.apply(l.size());
|
||||
nb.begin(l.size());
|
||||
for (Integer i : l) {
|
||||
nb.accept((int) i);
|
||||
}
|
||||
nb.end();
|
||||
|
||||
Node.OfInt n = nb.build();
|
||||
assertEquals(n.count(), l.size());
|
||||
|
||||
{
|
||||
List<Integer> _l = new ArrayList<>();
|
||||
n.forEach((IntConsumer) _l::add);
|
||||
|
||||
assertContents(_l, l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Node.Builder.OfLong
|
||||
|
||||
@DataProvider(name = "Node.Builder<Long>")
|
||||
public Object[][] createLongNodeBuilders() {
|
||||
List<List<Long>> ls = new ArrayList<>();
|
||||
for (int size : sizes) {
|
||||
List<Long> l = new ArrayList<>();
|
||||
for (long i = 0; i < size; i++) {
|
||||
l.add(i);
|
||||
}
|
||||
ls.add(l);
|
||||
}
|
||||
|
||||
List<Function<Integer, Node.Builder<Long>>> ms = Arrays.asList(
|
||||
s -> Nodes.longBuilder(),
|
||||
s -> Nodes.longBuilder(s)
|
||||
);
|
||||
|
||||
Object[][] params = new Object[ls.size() * ms.size()][];
|
||||
int i = 0;
|
||||
for (List<Long> l : ls) {
|
||||
for (Function<Integer, Node.Builder<Long>> m : ms) {
|
||||
params[i++] = new Object[]{l, m};
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "Node.Builder<Long>")
|
||||
public void testLongIteration(List<Long> l, Function<Integer, Node.Builder.OfLong> m) {
|
||||
Node.Builder.OfLong nb = m.apply(l.size());
|
||||
nb.begin(l.size());
|
||||
for (Long i : l) {
|
||||
nb.accept((long) i);
|
||||
}
|
||||
nb.end();
|
||||
|
||||
Node.OfLong n = nb.build();
|
||||
assertEquals(n.count(), l.size());
|
||||
|
||||
{
|
||||
List<Long> _l = new ArrayList<>();
|
||||
n.forEach((LongConsumer) _l::add);
|
||||
|
||||
assertContents(_l, l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Node.Builder.OfDouble
|
||||
|
||||
@DataProvider(name = "Node.Builder<Double>")
|
||||
public Object[][] createDoubleNodeBuilders() {
|
||||
List<List<Double>> ls = new ArrayList<>();
|
||||
for (int size : sizes) {
|
||||
List<Double> l = new ArrayList<>();
|
||||
for (long i = 0; i < size; i++) {
|
||||
l.add((double) i);
|
||||
}
|
||||
ls.add(l);
|
||||
}
|
||||
|
||||
List<Function<Integer, Node.Builder<Double>>> ms = Arrays.asList(
|
||||
s -> Nodes.doubleBuilder(),
|
||||
s -> Nodes.doubleBuilder(s)
|
||||
);
|
||||
|
||||
Object[][] params = new Object[ls.size() * ms.size()][];
|
||||
int i = 0;
|
||||
for (List<Double> l : ls) {
|
||||
for (Function<Integer, Node.Builder<Double>> m : ms) {
|
||||
params[i++] = new Object[]{l, m};
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "Node.Builder<Double>")
|
||||
public void testDoubleIteration(List<Double> l, Function<Integer, Node.Builder.OfDouble> m) {
|
||||
Node.Builder.OfDouble nb = m.apply(l.size());
|
||||
nb.begin(l.size());
|
||||
for (Double i : l) {
|
||||
nb.accept((double) i);
|
||||
}
|
||||
nb.end();
|
||||
|
||||
Node.OfDouble n = nb.build();
|
||||
assertEquals(n.count(), l.size());
|
||||
|
||||
{
|
||||
List<Double> _l = new ArrayList<>();
|
||||
n.forEach((DoubleConsumer) _l::add);
|
||||
|
||||
assertContents(_l, l);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.SpliteratorTestHelper;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class NodeTest extends OpTestCase {
|
||||
|
||||
@DataProvider(name = "nodes")
|
||||
public Object[][] createSizes() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : Arrays.asList(0, 1, 4, 15, 16, 17, 127, 128, 129, 1000)) {
|
||||
Integer[] array = new Integer[size];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i;
|
||||
}
|
||||
|
||||
List<Node<Integer>> nodes = new ArrayList<>();
|
||||
nodes.add(Nodes.node(array));
|
||||
nodes.add(Nodes.node(Arrays.asList(array)));
|
||||
nodes.add(degenerateTree(Arrays.asList(array).iterator()));
|
||||
nodes.add(tree(Arrays.asList(array), l -> Nodes.node(l.toArray(new Integer[l.size()]))));
|
||||
nodes.add(tree(Arrays.asList(array), l -> Nodes.node(l)));
|
||||
nodes.add(fill(array, Nodes.builder(array.length, LambdaTestHelpers.integerArrayGenerator)));
|
||||
nodes.add(fill(array, Nodes.builder()));
|
||||
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
params.add(new Object[]{array, nodes.get(i)});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
Node<Integer> fill(Integer[] array, Node.Builder<Integer> nb) {
|
||||
nb.begin(array.length);
|
||||
for (Integer i : array) {
|
||||
nb.accept(i);
|
||||
}
|
||||
nb.end();
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
Node<Integer> degenerateTree(Iterator<Integer> it) {
|
||||
if (!it.hasNext()) {
|
||||
return Nodes.node(Collections.emptyList());
|
||||
}
|
||||
|
||||
Integer i = it.next();
|
||||
if (it.hasNext()) {
|
||||
return new Nodes.ConcNode<Integer>(Nodes.node(new Integer[] {i}), degenerateTree(it));
|
||||
}
|
||||
else {
|
||||
return Nodes.node(new Integer[]{i});
|
||||
}
|
||||
}
|
||||
|
||||
Node<Integer> tree(List<Integer> l, Function<List<Integer>, Node<Integer>> m) {
|
||||
if (l.size() < 3) {
|
||||
return m.apply(l);
|
||||
}
|
||||
else {
|
||||
return new Nodes.ConcNode<>(
|
||||
tree(l.subList(0, l.size() / 2), m),
|
||||
tree(l.subList(l.size() / 2, l.size()), m ));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testAsArray(Integer[] array, Node<Integer> n) {
|
||||
assertEquals(n.asArray(LambdaTestHelpers.integerArrayGenerator), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testFlattenAsArray(Integer[] array, Node<Integer> n) {
|
||||
assertEquals(Nodes.flatten(n, LambdaTestHelpers.integerArrayGenerator)
|
||||
.asArray(LambdaTestHelpers.integerArrayGenerator), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testCopyTo(Integer[] array, Node<Integer> n) {
|
||||
Integer[] copy = new Integer[(int) n.count()];
|
||||
n.copyInto(copy, 0);
|
||||
|
||||
assertEquals(copy, array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes", groups = { "serialization-hostile" })
|
||||
public void testForEach(Integer[] array, Node<Integer> n) {
|
||||
List<Integer> l = new ArrayList<>((int) n.count());
|
||||
n.forEach(e -> l.add(e));
|
||||
|
||||
assertEquals(l.toArray(), array);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testStreams(Integer[] array, Node<Integer> n) {
|
||||
TestData<Integer, Stream<Integer>> data = TestData.Factory.ofRefNode("Node", n);
|
||||
|
||||
exerciseOps(data, s -> s);
|
||||
|
||||
exerciseTerminalOps(data, s -> s.toArray());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testSpliterator(Integer[] array, Node<Integer> n) {
|
||||
SpliteratorTestHelper.testSpliterator(n::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "nodes")
|
||||
public void testTruncate(Integer[] array, Node<Integer> n) {
|
||||
int[] nums = new int[] { 0, 1, array.length / 2, array.length - 1, array.length };
|
||||
for (int start : nums)
|
||||
for (int end : nums) {
|
||||
if (start < 0 || end < 0 || end < start || end > array.length)
|
||||
continue;
|
||||
Node<Integer> slice = n.truncate(start, end, Integer[]::new);
|
||||
Integer[] asArray = slice.asArray(Integer[]::new);
|
||||
for (int k = start; k < end; k++)
|
||||
assertEquals(array[k], asArray[k - start]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
import java.util.SpliteratorTestHelper;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @bug 8012987
|
||||
*/
|
||||
@Test
|
||||
public class SliceSpliteratorTest extends LoggingTestCase {
|
||||
|
||||
static class UnorderedContentAsserter<T> implements SpliteratorTestHelper.ContentAsserter<T> {
|
||||
Collection<T> source;
|
||||
|
||||
UnorderedContentAsserter(Collection<T> source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertContents(Collection<T> actual, Collection<T> expected, boolean isOrdered) {
|
||||
if (isOrdered) {
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
else {
|
||||
assertEquals(actual.size(), expected.size());
|
||||
assertTrue(source.containsAll(actual));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface SliceTester {
|
||||
void test(int size, int skip, int limit);
|
||||
}
|
||||
|
||||
@DataProvider(name = "sliceSpliteratorDataProvider")
|
||||
public static Object[][] sliceSpliteratorDataProvider() {
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
|
||||
// SIZED/SUBSIZED slice spliterator
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Integer> source = IntStream.range(0, size).boxed().collect(toList());
|
||||
|
||||
SpliteratorTestHelper.testSpliterator(() -> {
|
||||
Spliterator<Integer> s = Arrays.spliterator(source.stream().toArray(Integer[]::new));
|
||||
|
||||
return new StreamSpliterators.SliceSpliterator.OfRef<>(s, skip, limit);
|
||||
});
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.SliceSpliterator.OfRef", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Integer> source = IntStream.range(0, size).boxed().collect(toList());
|
||||
|
||||
SpliteratorTestHelper.testIntSpliterator(() -> {
|
||||
Spliterator.OfInt s = Arrays.spliterator(source.stream().mapToInt(i->i).toArray());
|
||||
|
||||
return new StreamSpliterators.SliceSpliterator.OfInt(s, skip, limit);
|
||||
});
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.SliceSpliterator.OfInt", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Long> source = LongStream.range(0, size).boxed().collect(toList());
|
||||
|
||||
SpliteratorTestHelper.testLongSpliterator(() -> {
|
||||
Spliterator.OfLong s = Arrays.spliterator(source.stream().mapToLong(i->i).toArray());
|
||||
|
||||
return new StreamSpliterators.SliceSpliterator.OfLong(s, skip, limit);
|
||||
});
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.SliceSpliterator.OfLong", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Double> source = LongStream.range(0, size).asDoubleStream().boxed().collect(toList());
|
||||
|
||||
SpliteratorTestHelper.testDoubleSpliterator(() -> {
|
||||
Spliterator.OfDouble s = Arrays.spliterator(source.stream().mapToDouble(i->i).toArray());
|
||||
|
||||
return new StreamSpliterators.SliceSpliterator.OfDouble(s, skip, limit);
|
||||
});
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.SliceSpliterator.OfLong", r});
|
||||
}
|
||||
|
||||
|
||||
// Unordered slice spliterator
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Integer> source = IntStream.range(0, size).boxed().collect(toList());
|
||||
final UnorderedContentAsserter<Integer> uca = new UnorderedContentAsserter<>(source);
|
||||
|
||||
SpliteratorTestHelper.testSpliterator(() -> {
|
||||
Spliterator<Integer> s = Arrays.spliterator(source.stream().toArray(Integer[]::new));
|
||||
|
||||
return new StreamSpliterators.UnorderedSliceSpliterator.OfRef<>(s, skip, limit);
|
||||
}, uca);
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.UnorderedSliceSpliterator.OfRef", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Integer> source = IntStream.range(0, size).boxed().collect(toList());
|
||||
final UnorderedContentAsserter<Integer> uca = new UnorderedContentAsserter<>(source);
|
||||
|
||||
SpliteratorTestHelper.testIntSpliterator(() -> {
|
||||
Spliterator.OfInt s = Arrays.spliterator(source.stream().mapToInt(i->i).toArray());
|
||||
|
||||
return new StreamSpliterators.UnorderedSliceSpliterator.OfInt(s, skip, limit);
|
||||
}, uca);
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.UnorderedSliceSpliterator.OfInt", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Long> source = LongStream.range(0, size).boxed().collect(toList());
|
||||
final UnorderedContentAsserter<Long> uca = new UnorderedContentAsserter<>(source);
|
||||
|
||||
SpliteratorTestHelper.testLongSpliterator(() -> {
|
||||
Spliterator.OfLong s = Arrays.spliterator(source.stream().mapToLong(i->i).toArray());
|
||||
|
||||
return new StreamSpliterators.UnorderedSliceSpliterator.OfLong(s, skip, limit);
|
||||
}, uca);
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.UnorderedSliceSpliterator.OfLong", r});
|
||||
}
|
||||
|
||||
{
|
||||
SliceTester r = (size, skip, limit) -> {
|
||||
final Collection<Double> source = LongStream.range(0, size).asDoubleStream().boxed().collect(toList());
|
||||
final UnorderedContentAsserter<Double> uca = new UnorderedContentAsserter<>(source);
|
||||
|
||||
SpliteratorTestHelper.testDoubleSpliterator(() -> {
|
||||
Spliterator.OfDouble s = Arrays.spliterator(LongStream.range(0, SIZE).asDoubleStream().toArray());
|
||||
|
||||
return new StreamSpliterators.UnorderedSliceSpliterator.OfDouble(s, skip, limit);
|
||||
}, uca);
|
||||
};
|
||||
data.add(new Object[]{"StreamSpliterators.UnorderedSliceSpliterator.OfLong", r});
|
||||
}
|
||||
|
||||
return data.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
static final int SIZE = 256;
|
||||
|
||||
static final int STEP = 32;
|
||||
|
||||
@Test(dataProvider = "sliceSpliteratorDataProvider")
|
||||
public void testSliceSpliterator(String description, SliceTester r) {
|
||||
setContext("size", SIZE);
|
||||
for (int skip = 0; skip < SIZE; skip += STEP) {
|
||||
setContext("skip", skip);
|
||||
for (int limit = 0; limit < SIZE; limit += STEP) {
|
||||
setContext("limit", skip);
|
||||
r.test(SIZE, skip, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.DoubleConsumer;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
@Test
|
||||
public class SpinedBufferDoubleTest extends AbstractSpinedBufferTest {
|
||||
@DataProvider(name = "DoubleSpinedBuffer")
|
||||
public Object[][] createDoubleSpinedBuffer() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : SIZES) {
|
||||
// @@@ replace with double range when implemented
|
||||
double[] array = LongStream.range(0, size).asDoubleStream().toArray();
|
||||
SpinedBuffer.OfDouble sb = new SpinedBuffer.OfDouble();
|
||||
Arrays.stream(array).forEach(sb);
|
||||
|
||||
params.add(new Object[]{array, sb});
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleSpinedBuffer")
|
||||
public void testDoubleSpliterator(double[] array, SpinedBuffer.OfDouble sb) {
|
||||
assertEquals(sb.count(), array.length);
|
||||
assertEquals(sb.count(), sb.spliterator().getExactSizeIfKnown());
|
||||
|
||||
SpliteratorTestHelper.testDoubleSpliterator(sb::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleSpinedBuffer", groups = { "serialization-hostile" })
|
||||
public void testLongLastSplit(double[] array, SpinedBuffer.OfDouble sb) {
|
||||
Spliterator.OfDouble spliterator = sb.spliterator();
|
||||
Spliterator.OfDouble split = spliterator.trySplit();
|
||||
long splitSizes = (split == null) ? 0 : split.getExactSizeIfKnown();
|
||||
long lastSplitSize = spliterator.getExactSizeIfKnown();
|
||||
splitSizes += lastSplitSize;
|
||||
|
||||
assertEquals(splitSizes, array.length);
|
||||
|
||||
List<Double> contentOfLastSplit = new ArrayList<>();
|
||||
spliterator.forEachRemaining((DoubleConsumer) contentOfLastSplit::add);
|
||||
|
||||
assertEquals(contentOfLastSplit.size(), lastSplitSize);
|
||||
|
||||
List<Double> end = Arrays.stream(array)
|
||||
.boxed()
|
||||
.skip(array.length - lastSplitSize)
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(contentOfLastSplit, end);
|
||||
}
|
||||
|
||||
@Test(groups = { "serialization-hostile" })
|
||||
public void testDoubleSpinedBuffer() {
|
||||
List<Double> list1 = new ArrayList<>();
|
||||
List<Double> list2 = new ArrayList<>();
|
||||
SpinedBuffer.OfDouble sb = new SpinedBuffer.OfDouble();
|
||||
for (long i = 0; i < TEST_SIZE; i++) {
|
||||
list1.add((double) i);
|
||||
sb.accept((double) i);
|
||||
}
|
||||
PrimitiveIterator.OfDouble it = sb.iterator();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list2.add(it.nextDouble());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
assertEquals(list1, list2);
|
||||
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
assertEquals(sb.get(i), (double) i, Double.toString(i));
|
||||
}
|
||||
|
||||
list2.clear();
|
||||
sb.forEach((double i) -> list2.add(i));
|
||||
assertEquals(list1, list2);
|
||||
double[] array = sb.asPrimitiveArray();
|
||||
list2.clear();
|
||||
for (double i : array) {
|
||||
list2.add(i);
|
||||
}
|
||||
assertEquals(list1, list2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
@Test
|
||||
public class SpinedBufferIntTest extends AbstractSpinedBufferTest {
|
||||
@DataProvider(name = "IntSpinedBuffer")
|
||||
public Object[][] createIntSpinedBuffer() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : SIZES) {
|
||||
int[] array = IntStream.range(0, size).toArray();
|
||||
SpinedBuffer.OfInt sb = new SpinedBuffer.OfInt();
|
||||
Arrays.stream(array).forEach(sb);
|
||||
|
||||
params.add(new Object[]{array, sb});
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntSpinedBuffer")
|
||||
public void testIntSpliterator(int[] array, SpinedBuffer.OfInt sb) {
|
||||
assertEquals(sb.count(), array.length);
|
||||
assertEquals(sb.count(), sb.spliterator().getExactSizeIfKnown());
|
||||
|
||||
SpliteratorTestHelper.testIntSpliterator(sb::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntSpinedBuffer", groups = { "serialization-hostile" })
|
||||
public void testIntLastSplit(int[] array, SpinedBuffer.OfInt sb) {
|
||||
Spliterator.OfInt spliterator = sb.spliterator();
|
||||
Spliterator.OfInt split = spliterator.trySplit();
|
||||
long splitSizes = (split == null) ? 0 : split.getExactSizeIfKnown();
|
||||
long lastSplitSize = spliterator.getExactSizeIfKnown();
|
||||
splitSizes += lastSplitSize;
|
||||
|
||||
assertEquals(splitSizes, array.length);
|
||||
|
||||
List<Integer> contentOfLastSplit = new ArrayList<>();
|
||||
spliterator.forEachRemaining((IntConsumer) contentOfLastSplit::add);
|
||||
|
||||
assertEquals(contentOfLastSplit.size(), lastSplitSize);
|
||||
|
||||
List<Integer> end = Arrays.stream(array)
|
||||
.boxed()
|
||||
.skip(array.length - lastSplitSize)
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(contentOfLastSplit, end);
|
||||
}
|
||||
|
||||
@Test(groups = { "serialization-hostile" })
|
||||
public void testIntSpinedBuffer() {
|
||||
List<Integer> list1 = new ArrayList<>();
|
||||
List<Integer> list2 = new ArrayList<>();
|
||||
SpinedBuffer.OfInt sb = new SpinedBuffer.OfInt();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list1.add(i);
|
||||
sb.accept(i);
|
||||
}
|
||||
PrimitiveIterator.OfInt it = sb.iterator();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list2.add(it.nextInt());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
assertEquals(list1, list2);
|
||||
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
assertEquals(sb.get(i), i, Integer.toString(i));
|
||||
}
|
||||
|
||||
list2.clear();
|
||||
sb.forEach((int i) -> list2.add(i));
|
||||
assertEquals(list1, list2);
|
||||
int[] array = sb.asPrimitiveArray();
|
||||
list2.clear();
|
||||
for (int i : array) {
|
||||
list2.add(i);
|
||||
}
|
||||
assertEquals(list1, list2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
@Test
|
||||
public class SpinedBufferIntegerTest extends AbstractSpinedBufferTest {
|
||||
@DataProvider(name = "SpinedBuffer")
|
||||
public Object[][] createSpinedBuffer() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : SIZES) {
|
||||
int[] array = IntStream.range(0, size).toArray();
|
||||
|
||||
SpinedBuffer<Integer> sb = new SpinedBuffer<>();
|
||||
Arrays.stream(array).boxed().forEach(sb);
|
||||
params.add(new Object[]{array, sb});
|
||||
|
||||
sb = new SpinedBuffer<>(size / 2);
|
||||
Arrays.stream(array).boxed().forEach(sb);
|
||||
params.add(new Object[]{array, sb});
|
||||
|
||||
sb = new SpinedBuffer<>(size);
|
||||
Arrays.stream(array).boxed().forEach(sb);
|
||||
params.add(new Object[]{array, sb});
|
||||
|
||||
sb = new SpinedBuffer<>(size * 2);
|
||||
Arrays.stream(array).boxed().forEach(sb);
|
||||
params.add(new Object[]{array, sb});
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "SpinedBuffer")
|
||||
public void testSpliterator(int[] array, SpinedBuffer<Integer> sb) {
|
||||
assertEquals(sb.count(), array.length);
|
||||
assertEquals(sb.count(), sb.spliterator().getExactSizeIfKnown());
|
||||
|
||||
SpliteratorTestHelper.testSpliterator(sb::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "SpinedBuffer", groups = { "serialization-hostile" })
|
||||
public void testLastSplit(int[] array, SpinedBuffer<Integer> sb) {
|
||||
Spliterator<Integer> spliterator = sb.spliterator();
|
||||
Spliterator<Integer> split = spliterator.trySplit();
|
||||
long splitSizes = (split == null) ? 0 : split.getExactSizeIfKnown();
|
||||
long lastSplitSize = spliterator.getExactSizeIfKnown();
|
||||
splitSizes += lastSplitSize;
|
||||
|
||||
assertEquals(splitSizes, array.length);
|
||||
|
||||
List<Integer> contentOfLastSplit = new ArrayList<>();
|
||||
spliterator.forEachRemaining(contentOfLastSplit::add);
|
||||
|
||||
assertEquals(contentOfLastSplit.size(), lastSplitSize);
|
||||
|
||||
List<Integer> end = Arrays.stream(array)
|
||||
.boxed()
|
||||
.skip(array.length - lastSplitSize)
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(contentOfLastSplit, end);
|
||||
}
|
||||
|
||||
@Test(groups = { "serialization-hostile" })
|
||||
public void testSpinedBuffer() {
|
||||
List<Integer> list1 = new ArrayList<>();
|
||||
List<Integer> list2 = new ArrayList<>();
|
||||
SpinedBuffer<Integer> sb = new SpinedBuffer<>();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list1.add(i);
|
||||
sb.accept(i);
|
||||
}
|
||||
Iterator<Integer> it = sb.iterator();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list2.add(it.next());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
assertEquals(list1, list2);
|
||||
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
assertEquals(sb.get(i), (Integer) i, Integer.toString(i));
|
||||
}
|
||||
|
||||
list2.clear();
|
||||
sb.forEach(list2::add);
|
||||
assertEquals(list1, list2);
|
||||
Integer[] array = sb.asArray(LambdaTestHelpers.integerArrayGenerator);
|
||||
list2.clear();
|
||||
for (Integer i : array) {
|
||||
list2.add(i);
|
||||
}
|
||||
assertEquals(list1, list2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.LongConsumer;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
@Test
|
||||
public class SpinedBufferLongTest extends AbstractSpinedBufferTest {
|
||||
@DataProvider(name = "LongSpinedBuffer")
|
||||
public Object[][] createLongSpinedBuffer() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
|
||||
for (int size : SIZES) {
|
||||
long[] array = LongStream.range(0, size).toArray();
|
||||
SpinedBuffer.OfLong sb = new SpinedBuffer.OfLong();
|
||||
Arrays.stream(array).forEach(sb);
|
||||
|
||||
params.add(new Object[]{array, sb});
|
||||
}
|
||||
|
||||
return params.toArray(new Object[0][]);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongSpinedBuffer")
|
||||
public void testLongSpliterator(long[] array, SpinedBuffer.OfLong sb) {
|
||||
assertEquals(sb.count(), array.length);
|
||||
assertEquals(sb.count(), sb.spliterator().getExactSizeIfKnown());
|
||||
|
||||
SpliteratorTestHelper.testLongSpliterator(sb::spliterator);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongSpinedBuffer", groups = { "serialization-hostile" })
|
||||
public void testLongLastSplit(long[] array, SpinedBuffer.OfLong sb) {
|
||||
Spliterator.OfLong spliterator = sb.spliterator();
|
||||
Spliterator.OfLong split = spliterator.trySplit();
|
||||
long splitSizes = (split == null) ? 0 : split.getExactSizeIfKnown();
|
||||
long lastSplitSize = spliterator.getExactSizeIfKnown();
|
||||
splitSizes += lastSplitSize;
|
||||
|
||||
assertEquals(splitSizes, array.length);
|
||||
|
||||
List<Long> contentOfLastSplit = new ArrayList<>();
|
||||
spliterator.forEachRemaining((LongConsumer) contentOfLastSplit::add);
|
||||
|
||||
assertEquals(contentOfLastSplit.size(), lastSplitSize);
|
||||
|
||||
List<Long> end = Arrays.stream(array)
|
||||
.boxed()
|
||||
.skip(array.length - lastSplitSize)
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(contentOfLastSplit, end);
|
||||
}
|
||||
|
||||
@Test(groups = { "serialization-hostile" })
|
||||
public void testLongSpinedBuffer() {
|
||||
List<Long> list1 = new ArrayList<>();
|
||||
List<Long> list2 = new ArrayList<>();
|
||||
SpinedBuffer.OfLong sb = new SpinedBuffer.OfLong();
|
||||
for (long i = 0; i < TEST_SIZE; i++) {
|
||||
list1.add(i);
|
||||
sb.accept(i);
|
||||
}
|
||||
PrimitiveIterator.OfLong it = sb.iterator();
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
list2.add(it.nextLong());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
assertEquals(list1, list2);
|
||||
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
assertEquals(sb.get(i), i, Long.toString(i));
|
||||
}
|
||||
|
||||
list2.clear();
|
||||
sb.forEach((long i) -> list2.add(i));
|
||||
assertEquals(list1, list2);
|
||||
long[] array = sb.asPrimitiveArray();
|
||||
list2.clear();
|
||||
for (long i : array) {
|
||||
list2.add(i);
|
||||
}
|
||||
assertEquals(list1, list2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamOpFlag;
|
||||
import java.util.stream.Streams;
|
||||
|
||||
import static java.util.stream.StreamOpFlag.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* StreamFlagsTest
|
||||
*
|
||||
* @author Brian Goetz
|
||||
*/
|
||||
@Test
|
||||
public class StreamFlagsTest {
|
||||
Stream<String> arrayList = new ArrayList<String>().stream();
|
||||
Stream<String> linkedList = new LinkedList<String>().stream();
|
||||
Stream<String> hashSet = new HashSet<String>().stream();
|
||||
Stream<String> treeSet = new TreeSet<String>().stream();
|
||||
Stream<String> linkedHashSet = new LinkedHashSet<String>().stream();
|
||||
Stream<String> repeat = Stream.generate(() -> "");
|
||||
|
||||
Stream<?>[] streams = { arrayList, linkedList, hashSet, treeSet, linkedHashSet, repeat };
|
||||
|
||||
private void assertFlags(int value, EnumSet<StreamOpFlag> setFlags, EnumSet<StreamOpFlag> clearFlags) {
|
||||
for (StreamOpFlag flag : setFlags)
|
||||
assertTrue(flag.isKnown(value));
|
||||
for (StreamOpFlag flag : clearFlags)
|
||||
assertTrue(!flag.isKnown(value));
|
||||
}
|
||||
|
||||
public void testBaseStreams() {
|
||||
Stream<String> arrayList = new ArrayList<String>().stream();
|
||||
Stream<String> linkedList = new LinkedList<String>().stream();
|
||||
Stream<String> hashSet = new HashSet<String>().stream();
|
||||
Stream<String> treeSet = new TreeSet<String>().stream();
|
||||
Stream<String> linkedHashSet = new LinkedHashSet<String>().stream();
|
||||
Stream<String> repeat = Stream.generate(() -> "");
|
||||
|
||||
assertFlags(OpTestCase.getStreamFlags(arrayList),
|
||||
EnumSet.of(ORDERED, SIZED),
|
||||
EnumSet.of(DISTINCT, SORTED, SHORT_CIRCUIT));
|
||||
assertFlags(OpTestCase.getStreamFlags(linkedList),
|
||||
EnumSet.of(ORDERED, SIZED),
|
||||
EnumSet.of(DISTINCT, SORTED, SHORT_CIRCUIT));
|
||||
assertFlags(OpTestCase.getStreamFlags(hashSet),
|
||||
EnumSet.of(SIZED, DISTINCT),
|
||||
EnumSet.of(ORDERED, SORTED, SHORT_CIRCUIT));
|
||||
assertFlags(OpTestCase.getStreamFlags(treeSet),
|
||||
EnumSet.of(ORDERED, SIZED, DISTINCT, SORTED),
|
||||
EnumSet.of(SHORT_CIRCUIT));
|
||||
assertFlags(OpTestCase.getStreamFlags(linkedHashSet),
|
||||
EnumSet.of(ORDERED, DISTINCT, SIZED),
|
||||
EnumSet.of(SORTED, SHORT_CIRCUIT));
|
||||
assertFlags(OpTestCase.getStreamFlags(repeat),
|
||||
EnumSet.noneOf(StreamOpFlag.class),
|
||||
EnumSet.of(DISTINCT, SORTED, SHORT_CIRCUIT));
|
||||
}
|
||||
|
||||
public void testFilter() {
|
||||
for (Stream<?> s : streams) {
|
||||
int baseFlags = OpTestCase.getStreamFlags(s);
|
||||
int filteredFlags = OpTestCase.getStreamFlags(s.filter((Object e) -> true));
|
||||
int expectedFlags = baseFlags & ~SIZED.set();
|
||||
|
||||
assertEquals(filteredFlags, expectedFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,386 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToDoubleFunction;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.function.ToLongFunction;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.StreamOpFlag.*;
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
@Test
|
||||
public class StreamOpFlagsTest {
|
||||
|
||||
public void testNullCombine() {
|
||||
int sourceFlags = StreamOpFlag.IS_SIZED;
|
||||
|
||||
assertEquals(sourceFlags, toStreamFlags(combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE)));
|
||||
}
|
||||
|
||||
public void testInitialOpFlagsFromSourceFlags() {
|
||||
List<StreamOpFlag> flags = new ArrayList<>(StreamOpFlagTestHelper.allStreamFlags());
|
||||
for (int i = 0; i < (1 << flags.size()); i++) {
|
||||
int sourceFlags = 0;
|
||||
for (int f = 0; f < flags.size(); f++) {
|
||||
if ((i & (1 << f)) != 0) {
|
||||
sourceFlags |= flags.get(f).set();
|
||||
}
|
||||
}
|
||||
|
||||
int opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
assertEquals(opsFlags, (~(sourceFlags << 1)) & StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSameCombine() {
|
||||
for (StreamOpFlag f : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
int sourceFlags = f.set();
|
||||
int opsFlags;
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f.set(), opsFlags);
|
||||
assertEquals(sourceFlags, toStreamFlags(opsFlags));
|
||||
}
|
||||
}
|
||||
|
||||
public void testOpClear() {
|
||||
for (StreamOpFlag f : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
// Clear when source not set
|
||||
int sourceFlags = 0;
|
||||
int opsFlags;
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f.clear(), opsFlags);
|
||||
assertEquals(sourceFlags, toStreamFlags(opsFlags));
|
||||
|
||||
// Clear when source set
|
||||
sourceFlags = f.set();
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f.clear(), opsFlags);
|
||||
assertEquals(0, toStreamFlags(opsFlags));
|
||||
}
|
||||
}
|
||||
|
||||
public void testOpInject() {
|
||||
for (StreamOpFlag f : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
// Set when source not set
|
||||
int sourceFlags = 0;
|
||||
int opsFlags;
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f.set(), opsFlags);
|
||||
assertEquals(f.set(), toStreamFlags(opsFlags));
|
||||
|
||||
// Set when source set
|
||||
sourceFlags = f.set();
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f.set(), opsFlags);
|
||||
assertEquals(sourceFlags, toStreamFlags(opsFlags));
|
||||
}
|
||||
}
|
||||
|
||||
public void testPairSet() {
|
||||
List<Integer> sourceFlagsList
|
||||
= StreamOpFlagTestHelper.allStreamFlags().stream().map(StreamOpFlag::set).collect(toList());
|
||||
sourceFlagsList.add(0, 0);
|
||||
|
||||
for (int sourceFlags : sourceFlagsList) {
|
||||
for (StreamOpFlag f1 : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
for (StreamOpFlag f2 : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
int opsFlags;
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f1.set(), opsFlags);
|
||||
opsFlags = combineOpFlags(f2.set(), opsFlags);
|
||||
assertEquals(sourceFlags | f1.set() | f2.set(), toStreamFlags(opsFlags));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testPairSetAndClear() {
|
||||
List<Integer> sourceFlagsList
|
||||
= StreamOpFlagTestHelper.allStreamFlags().stream().map(StreamOpFlag::set).collect(toList());
|
||||
sourceFlagsList.add(0, 0);
|
||||
|
||||
for (int sourceFlags : sourceFlagsList) {
|
||||
for (StreamOpFlag f1 : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
for (StreamOpFlag f2 : StreamOpFlagTestHelper.allStreamFlags()) {
|
||||
int opsFlags;
|
||||
|
||||
opsFlags = combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
opsFlags = combineOpFlags(f1.set(), opsFlags);
|
||||
opsFlags = combineOpFlags(f2.clear(), opsFlags);
|
||||
if (f1 == f2)
|
||||
assertEquals((f2.set() == sourceFlags) ? 0 : sourceFlags, toStreamFlags(opsFlags));
|
||||
else
|
||||
assertEquals((f2.set() == sourceFlags) ? f1.set() : sourceFlags | f1.set(), toStreamFlags(opsFlags));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testShortCircuit() {
|
||||
int opsFlags = combineOpFlags(0, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
assertFalse(StreamOpFlag.SHORT_CIRCUIT.isKnown(opsFlags));
|
||||
|
||||
opsFlags = combineOpFlags(StreamOpFlag.IS_SHORT_CIRCUIT, opsFlags);
|
||||
assertTrue(StreamOpFlag.SHORT_CIRCUIT.isKnown(opsFlags));
|
||||
|
||||
opsFlags = combineOpFlags(0, opsFlags);
|
||||
assertTrue(StreamOpFlag.SHORT_CIRCUIT.isKnown(opsFlags));
|
||||
}
|
||||
|
||||
public void testApplySourceFlags() {
|
||||
int sourceFlags = StreamOpFlag.IS_SIZED | StreamOpFlag.IS_DISTINCT;
|
||||
|
||||
List<Integer> ops = Arrays.asList(StreamOpFlag.NOT_SIZED, StreamOpFlag.IS_ORDERED | StreamOpFlag.IS_SORTED);
|
||||
|
||||
int opsFlags = StreamOpFlag.combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE);
|
||||
for (int opFlags : ops) {
|
||||
opsFlags = combineOpFlags(opFlags, opsFlags);
|
||||
}
|
||||
assertFalse(StreamOpFlag.SIZED.isKnown(opsFlags));
|
||||
assertTrue(StreamOpFlag.SIZED.isCleared(opsFlags));
|
||||
assertFalse(StreamOpFlag.SIZED.isPreserved(opsFlags));
|
||||
assertTrue(StreamOpFlag.DISTINCT.isKnown(opsFlags));
|
||||
assertFalse(StreamOpFlag.DISTINCT.isCleared(opsFlags));
|
||||
assertFalse(StreamOpFlag.DISTINCT.isPreserved(opsFlags));
|
||||
assertTrue(StreamOpFlag.SORTED.isKnown(opsFlags));
|
||||
assertFalse(StreamOpFlag.SORTED.isCleared(opsFlags));
|
||||
assertFalse(StreamOpFlag.SORTED.isPreserved(opsFlags));
|
||||
assertTrue(StreamOpFlag.ORDERED.isKnown(opsFlags));
|
||||
assertFalse(StreamOpFlag.ORDERED.isCleared(opsFlags));
|
||||
assertFalse(StreamOpFlag.ORDERED.isPreserved(opsFlags));
|
||||
|
||||
int streamFlags = toStreamFlags(opsFlags);
|
||||
assertFalse(StreamOpFlag.SIZED.isKnown(streamFlags));
|
||||
assertTrue(StreamOpFlag.DISTINCT.isKnown(streamFlags));
|
||||
assertTrue(StreamOpFlag.SORTED.isKnown(streamFlags));
|
||||
assertTrue(StreamOpFlag.ORDERED.isKnown(streamFlags));
|
||||
}
|
||||
|
||||
public void testSpliteratorMask() {
|
||||
assertSpliteratorMask(StreamOpFlag.DISTINCT.set(), StreamOpFlag.IS_DISTINCT);
|
||||
assertSpliteratorMask(StreamOpFlag.DISTINCT.clear(), 0);
|
||||
|
||||
assertSpliteratorMask(StreamOpFlag.SORTED.set(), StreamOpFlag.IS_SORTED);
|
||||
assertSpliteratorMask(StreamOpFlag.SORTED.clear(), 0);
|
||||
|
||||
assertSpliteratorMask(StreamOpFlag.ORDERED.set(), StreamOpFlag.IS_ORDERED);
|
||||
assertSpliteratorMask(StreamOpFlag.ORDERED.clear(), 0);
|
||||
|
||||
assertSpliteratorMask(StreamOpFlag.SIZED.set(), StreamOpFlag.IS_SIZED);
|
||||
assertSpliteratorMask(StreamOpFlag.SIZED.clear(), 0);
|
||||
|
||||
assertSpliteratorMask(StreamOpFlag.SHORT_CIRCUIT.set(), 0);
|
||||
assertSpliteratorMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertSpliteratorMask(int actual, int expected) {
|
||||
assertEquals(actual & StreamOpFlag.SPLITERATOR_CHARACTERISTICS_MASK, expected);
|
||||
}
|
||||
|
||||
public void testStreamMask() {
|
||||
assertStreamMask(StreamOpFlag.DISTINCT.set(), StreamOpFlag.IS_DISTINCT);
|
||||
assertStreamMask(StreamOpFlag.DISTINCT.clear(), 0);
|
||||
|
||||
assertStreamMask(StreamOpFlag.SORTED.set(), StreamOpFlag.IS_SORTED);
|
||||
assertStreamMask(StreamOpFlag.SORTED.clear(), 0);
|
||||
|
||||
assertStreamMask(StreamOpFlag.ORDERED.set(), StreamOpFlag.IS_ORDERED);
|
||||
assertStreamMask(StreamOpFlag.ORDERED.clear(), 0);
|
||||
|
||||
assertStreamMask(StreamOpFlag.SIZED.set(), StreamOpFlag.IS_SIZED);
|
||||
assertStreamMask(StreamOpFlag.SIZED.clear(), 0);
|
||||
|
||||
assertStreamMask(StreamOpFlag.SHORT_CIRCUIT.set(), 0);
|
||||
assertStreamMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertStreamMask(int actual, int expected) {
|
||||
assertEquals(actual & StreamOpFlag.STREAM_MASK, expected);
|
||||
}
|
||||
|
||||
public void testOpMask() {
|
||||
assertOpMask(StreamOpFlag.DISTINCT.set(), StreamOpFlag.IS_DISTINCT);
|
||||
assertOpMask(StreamOpFlag.DISTINCT.clear(), StreamOpFlag.NOT_DISTINCT);
|
||||
|
||||
assertOpMask(StreamOpFlag.SORTED.set(), StreamOpFlag.IS_SORTED);
|
||||
assertOpMask(StreamOpFlag.SORTED.clear(), StreamOpFlag.NOT_SORTED);
|
||||
|
||||
assertOpMask(StreamOpFlag.ORDERED.set(), StreamOpFlag.IS_ORDERED);
|
||||
assertOpMask(StreamOpFlag.ORDERED.clear(), StreamOpFlag.NOT_ORDERED);
|
||||
|
||||
assertOpMask(StreamOpFlag.SIZED.set(), 0);
|
||||
assertOpMask(StreamOpFlag.SIZED.clear(), StreamOpFlag.NOT_SIZED);
|
||||
|
||||
assertOpMask(StreamOpFlag.SHORT_CIRCUIT.set(), StreamOpFlag.IS_SHORT_CIRCUIT);
|
||||
assertOpMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertOpMask(int actual, int expected) {
|
||||
assertEquals(actual & StreamOpFlag.OP_MASK, expected);
|
||||
}
|
||||
|
||||
public void testTerminalOpMask() {
|
||||
assertTerminalOpMask(StreamOpFlag.DISTINCT.set(), 0);
|
||||
assertTerminalOpMask(StreamOpFlag.DISTINCT.clear(), 0);
|
||||
|
||||
assertTerminalOpMask(StreamOpFlag.SORTED.set(), 0);
|
||||
assertTerminalOpMask(StreamOpFlag.SORTED.clear(), 0);
|
||||
|
||||
assertTerminalOpMask(StreamOpFlag.ORDERED.set(), 0);
|
||||
assertTerminalOpMask(StreamOpFlag.ORDERED.clear(), StreamOpFlag.NOT_ORDERED);
|
||||
|
||||
assertTerminalOpMask(StreamOpFlag.SIZED.set(), 0);
|
||||
assertTerminalOpMask(StreamOpFlag.SIZED.clear(), 0);
|
||||
|
||||
assertTerminalOpMask(StreamOpFlag.SHORT_CIRCUIT.set(), StreamOpFlag.IS_SHORT_CIRCUIT);
|
||||
assertTerminalOpMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertTerminalOpMask(int actual, int expected) {
|
||||
assertEquals(actual & StreamOpFlag.TERMINAL_OP_MASK, expected);
|
||||
}
|
||||
|
||||
public void testUpstreamTerminalOpMask() {
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.DISTINCT.set(), 0);
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.DISTINCT.clear(), 0);
|
||||
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SORTED.set(), 0);
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SORTED.clear(), 0);
|
||||
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.ORDERED.set(), 0);
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.ORDERED.clear(), StreamOpFlag.NOT_ORDERED);
|
||||
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SIZED.set(), 0);
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SIZED.clear(), 0);
|
||||
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SHORT_CIRCUIT.set(), 0);
|
||||
assertUpstreamTerminalOpMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertUpstreamTerminalOpMask(int actual, int expected) {
|
||||
assertEquals(actual & StreamOpFlag.UPSTREAM_TERMINAL_OP_MASK, expected);
|
||||
}
|
||||
|
||||
public void testSpliteratorCharacteristics() {
|
||||
assertEquals(Spliterator.DISTINCT, StreamOpFlag.IS_DISTINCT);
|
||||
assertEquals(Spliterator.SORTED, StreamOpFlag.IS_SORTED);
|
||||
assertEquals(Spliterator.ORDERED, StreamOpFlag.IS_ORDERED);
|
||||
assertEquals(Spliterator.SIZED, StreamOpFlag.IS_SIZED);
|
||||
|
||||
List<Integer> others = Arrays.asList(Spliterator.NONNULL, Spliterator.IMMUTABLE,
|
||||
Spliterator.CONCURRENT, Spliterator.SUBSIZED);
|
||||
for (int c : others) {
|
||||
assertNotEquals(c, StreamOpFlag.IS_SHORT_CIRCUIT);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSpliteratorCharacteristicsMask() {
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.DISTINCT.set(), StreamOpFlag.IS_DISTINCT);
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.DISTINCT.clear(), 0);
|
||||
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SORTED.set(), StreamOpFlag.IS_SORTED);
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SORTED.clear(), 0);
|
||||
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.ORDERED.set(), StreamOpFlag.IS_ORDERED);
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.ORDERED.clear(), 0);
|
||||
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SIZED.set(), StreamOpFlag.IS_SIZED);
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SIZED.clear(), 0);
|
||||
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SHORT_CIRCUIT.set(), 0);
|
||||
assertSpliteratorCharacteristicsMask(StreamOpFlag.SHORT_CIRCUIT.clear(), 0);
|
||||
}
|
||||
|
||||
private void assertSpliteratorCharacteristicsMask(int actual, int expected) {
|
||||
assertEquals(StreamOpFlag.fromCharacteristics(actual), expected);
|
||||
}
|
||||
|
||||
public void testSpliteratorSorted() {
|
||||
class SortedEmptySpliterator<T extends Comparable<? super T>> implements Spliterator<T> {
|
||||
final Comparator<T> c;
|
||||
|
||||
SortedEmptySpliterator(Comparator<T> c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<T> trySplit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryAdvance(Consumer<? super T> action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int characteristics() {
|
||||
return Spliterator.SORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<? super T> getComparator() {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int flags = StreamOpFlag.fromCharacteristics(new SortedEmptySpliterator<>(null));
|
||||
assertEquals(flags, StreamOpFlag.IS_SORTED);
|
||||
}
|
||||
|
||||
{
|
||||
int flags = StreamOpFlag.fromCharacteristics(new SortedEmptySpliterator<>((a, b) -> 0));
|
||||
assertEquals(flags, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int flags = StreamOpFlag.fromCharacteristics(new SortedEmptySpliterator<String>(Comparator.naturalOrder()));
|
||||
assertEquals(flags, StreamOpFlag.IS_SORTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,441 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.util.stream;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
/**
|
||||
* StreamReuseTest
|
||||
*
|
||||
* @author Brian Goetz
|
||||
*/
|
||||
@Test
|
||||
public class StreamReuseTest {
|
||||
|
||||
private <T, U, E, S extends BaseStream<E, S>, D extends TestData<E, S>> void assertSecondFails(
|
||||
D data,
|
||||
Function<S, T> first,
|
||||
Function<S, U> second,
|
||||
Class<? extends Throwable> exception,
|
||||
String text) {
|
||||
S stream = data.stream();
|
||||
T fr = first.apply(stream);
|
||||
try {
|
||||
U sr = second.apply(stream);
|
||||
fail(text + " (seq)");
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (exception.isAssignableFrom(e.getClass())) {
|
||||
// Expected
|
||||
}
|
||||
else if (e instanceof Error)
|
||||
throw (Error) e;
|
||||
else if (e instanceof RuntimeException)
|
||||
throw (RuntimeException) e;
|
||||
else
|
||||
throw new AssertionError("Unexpected exception " + e.getClass(), e);
|
||||
}
|
||||
|
||||
stream = data.parallelStream();
|
||||
fr = first.apply(stream);
|
||||
try {
|
||||
U sr = second.apply(stream);
|
||||
fail(text + " (par)");
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (exception.isAssignableFrom(e.getClass())) {
|
||||
// Expected
|
||||
}
|
||||
else if (e instanceof Error)
|
||||
throw (Error) e;
|
||||
else if (e instanceof RuntimeException)
|
||||
throw (RuntimeException) e;
|
||||
else
|
||||
throw new AssertionError("Unexpected exception " + e.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// Stream
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testTwoStreams(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
(Stream<Integer> s) -> s.map(i -> i), (Stream<Integer> s) -> s.map(i -> i),
|
||||
IllegalStateException.class,
|
||||
"Stream map / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::distinct, (Stream<Integer> s) -> s.map(i -> i),
|
||||
IllegalStateException.class,
|
||||
"Stream distinct / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(Stream<Integer> s) -> s.map(i -> i), Stream::distinct,
|
||||
IllegalStateException.class,
|
||||
"Stream map / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::distinct, Stream::distinct,
|
||||
IllegalStateException.class,
|
||||
"Stream distinct / distinct succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testTwoTerminals(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
Stream::findFirst, Stream::findFirst,
|
||||
IllegalStateException.class,
|
||||
"Stream findFirst / findFirst succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testTerminalStream(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
Stream::findFirst, (Stream<Integer> s) -> s.map(i -> i),
|
||||
IllegalStateException.class,
|
||||
"Stream findFirst / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(Stream<Integer> s) -> s.map(i -> i), Stream::findFirst,
|
||||
IllegalStateException.class,
|
||||
"Stream map / findFirst succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::findFirst, Stream::distinct,
|
||||
IllegalStateException.class,
|
||||
"Stream findFirst / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::distinct, Stream::findFirst,
|
||||
IllegalStateException.class,
|
||||
"Stream distinct / findFirst succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testTwoIterators(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
Stream::iterator, Stream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream iterator / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testTerminalIterator(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
Stream::iterator, Stream::findFirst,
|
||||
IllegalStateException.class,
|
||||
"Stream iterator / findFirst succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::findFirst, Stream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream findFirst / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
|
||||
public void testStreamIterator(String name, TestData<Integer, Stream<Integer>> data) {
|
||||
assertSecondFails(data,
|
||||
Stream::iterator, (Stream<Integer> s) -> s.map(i -> i),
|
||||
IllegalStateException.class,
|
||||
"Stream iterator / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(Stream<Integer> s) -> s.map(i -> i), Stream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream map / iterator succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::iterator, Stream::distinct,
|
||||
IllegalStateException.class,
|
||||
"Stream iterator / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
Stream::distinct, Stream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream distinct / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
// IntStream
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testTwoStreams(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
(IntStream s) -> s.mapToObj(i -> i), (IntStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"IntStream map / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::distinct, (IntStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"IntStream distinct / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(IntStream s) -> s.mapToObj(i -> i), IntStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"IntStream map / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::distinct, IntStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"IntStream distinct / distinct succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testTwoTerminals(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
IntStream::sum, IntStream::sum,
|
||||
IllegalStateException.class,
|
||||
"IntStream sum / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testTerminalStream(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
IntStream::sum, (IntStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"IntStream sum / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(IntStream s) -> s.mapToObj(i -> i), IntStream::sum,
|
||||
IllegalStateException.class,
|
||||
"IntStream map / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::sum, IntStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"IntStream sum / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::distinct, IntStream::sum,
|
||||
IllegalStateException.class,
|
||||
"IntStream distinct / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testTwoIterators(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
IntStream::iterator, IntStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"IntStream iterator / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testTerminalIterator(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
IntStream::iterator, IntStream::sum,
|
||||
IllegalStateException.class,
|
||||
"IntStream iterator / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::sum, IntStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream sum / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
|
||||
public void testStreamIterator(String name, TestData.OfInt data) {
|
||||
assertSecondFails(data,
|
||||
IntStream::iterator, (IntStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"IntStream iterator / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(IntStream s) -> s.mapToObj(i -> i), IntStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"IntStream map / iterator succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::iterator, IntStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"IntStream iterator / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
IntStream::distinct, IntStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"IntStream distinct / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
// LongStream
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testTwoStreams(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
(LongStream s) -> s.mapToObj(i -> i), (LongStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"LongStream map / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::distinct, (LongStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"LongStream distinct / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(LongStream s) -> s.mapToObj(i -> i), LongStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"LongStream map / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::distinct, LongStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"LongStream distinct / distinct succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testTwoTerminals(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
LongStream::sum, LongStream::sum,
|
||||
IllegalStateException.class,
|
||||
"LongStream sum / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testTerminalStream(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
LongStream::sum, (LongStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"LongStream sum / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(LongStream s) -> s.mapToObj(i -> i), LongStream::sum,
|
||||
IllegalStateException.class,
|
||||
"LongStream map / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::sum, LongStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"LongStream sum / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::distinct, LongStream::sum,
|
||||
IllegalStateException.class,
|
||||
"LongStream distinct / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testTwoIterators(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
LongStream::iterator, LongStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"LongStream iterator / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testTerminalIterator(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
LongStream::iterator, LongStream::sum,
|
||||
IllegalStateException.class,
|
||||
"LongStream iterator / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::sum, LongStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream sum / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
|
||||
public void testStreamIterator(String name, TestData.OfLong data) {
|
||||
assertSecondFails(data,
|
||||
LongStream::iterator, (LongStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"LongStream iterator / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(LongStream s) -> s.mapToObj(i -> i), LongStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"LongStream map / iterator succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::iterator, LongStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"LongStream iterator / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
LongStream::distinct, LongStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"LongStream distinct / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
// DoubleStream
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testTwoStreams(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
(DoubleStream s) -> s.mapToObj(i -> i), (DoubleStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"DoubleStream map / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::distinct, (DoubleStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"DoubleStream distinct / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(DoubleStream s) -> s.mapToObj(i -> i), DoubleStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream map / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::distinct, DoubleStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream distinct / distinct succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testTwoTerminals(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
DoubleStream::sum, DoubleStream::sum,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream sum / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testTerminalStream(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
DoubleStream::sum, (DoubleStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"DoubleStream sum / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(DoubleStream s) -> s.mapToObj(i -> i), DoubleStream::sum,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream map / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::sum, DoubleStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream sum / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::distinct, DoubleStream::sum,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream distinct / sum succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testTwoIterators(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
DoubleStream::iterator, DoubleStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream iterator / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testTerminalIterator(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
DoubleStream::iterator, DoubleStream::sum,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream iterator / sum succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::sum, DoubleStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"Stream sum / iterator succeeded erroneously");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
|
||||
public void testStreamIterator(String name, TestData.OfDouble data) {
|
||||
assertSecondFails(data,
|
||||
DoubleStream::iterator, (DoubleStream s) -> s.mapToObj(i -> i),
|
||||
IllegalStateException.class,
|
||||
"DoubleStream iterator / map succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
(DoubleStream s) -> s.mapToObj(i -> i), DoubleStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream map / iterator succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::iterator, DoubleStream::distinct,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream iterator / distinct succeeded erroneously");
|
||||
assertSecondFails(data,
|
||||
DoubleStream::distinct, DoubleStream::iterator,
|
||||
IllegalStateException.class,
|
||||
"DoubleStream distinct / iterator succeeded erroneously");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
timeout.default.seconds=480
|
||||
Loading…
Add table
Add a link
Reference in a new issue