下面列出了java.util.stream.TestData#OfDouble ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test(dataProvider = "doubles")
public void testDoubles(TestData.OfDouble data, ResultAsserter<Iterable<Double>> ra) {
withData(data).
stream(s -> s).
without(DoubleStreamTestScenario.CLEAR_SIZED_SCENARIOS).
resultAsserter(ra).
exercise();
}
@Test(dataProvider = "DoubleStream.limit")
public void testDoubleUnorderedGenerator(String description, UnaryOperator<DoubleStream> fs) {
// Source is spliterator of infinite size
TestData.OfDouble generator = TestData.Factory.ofDoubleSupplier(
"[1.0, 1.0, ...]", () -> DoubleStream.generate(() -> 1.0));
withData(generator).
stream(s -> fs.apply(s.filter(i -> true).unordered())).
exercise();
}
@Test(dataProvider = "DoubleStream.limit")
public void testDoubleUnorderedIteration(String description, UnaryOperator<DoubleStream> fs) {
// Source is a right-balanced tree of infinite size
TestData.OfDouble iterator = TestData.Factory.ofDoubleSupplier(
"[1.0, 2.0, 3.0, ...]", () -> DoubleStream.iterate(1, i -> i + 1));
// Ref
withData(iterator).
stream(s -> fs.apply(s.unordered())).
resultAsserter(unorderedAsserter()).
exercise();
}
@Test
public void testDoubleSingleton() {
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier("[0, 1)", () -> DoubleStream.of(1));
withData(data).
stream(s -> s).
expectedResult(Collections.singletonList(1.0)).
exercise();
withData(data).
stream(s -> s.map(i -> i)).
expectedResult(Collections.singletonList(1.0)).
exercise();
}
private void testDoubleStreamBuilder(int size, Function<Integer, DoubleStream> supplier) {
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier(String.format("[0, %d)", size),
() -> supplier.apply(size));
withData(data).
stream(s -> s).
expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise();
withData(data).
stream(s -> s.map(i -> i)).
expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise();
}
@Test(dataProvider = "doubles")
public void testDoubles(TestData.OfDouble data, ResultAsserter<Iterable<Double>> ra) {
withData(data).
stream(s -> s).
without(DoubleStreamTestScenario.CLEAR_SIZED_SCENARIOS).
resultAsserter(ra).
exercise();
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleStream(String name, TestData.OfDouble data) {
for (DoublePredicate p : DOUBLE_PREDICATES) {
setContext("p", p);
for (Kind kind : Kind.values()) {
setContext("kind", kind);
exerciseTerminalOps(data, doubleKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(dpFalse), doubleKinds.get(kind).apply(p));
exerciseTerminalOps(data, s -> s.filter(dpEven), doubleKinds.get(kind).apply(p));
}
}
}
@Test(dataProvider = "DoubleStream.limit")
public void testDoubleUnorderedGenerator(String description, UnaryOperator<DoubleStream> fs) {
// Source is spliterator of infinite size
TestData.OfDouble generator = TestData.Factory.ofDoubleSupplier(
"[1.0, 1.0, ...]", () -> DoubleStream.generate(() -> 1.0));
withData(generator).
stream(s -> fs.apply(s.filter(i -> true).unordered())).
exercise();
}
@Test(dataProvider = "DoubleStream.limit")
public void testDoubleUnorderedIteration(String description, UnaryOperator<DoubleStream> fs) {
// Source is a right-balanced tree of infinite size
TestData.OfDouble iterator = TestData.Factory.ofDoubleSupplier(
"[1.0, 2.0, 3.0, ...]", () -> DoubleStream.iterate(1, i -> i + 1));
// Ref
withData(iterator).
stream(s -> fs.apply(s.unordered())).
resultAsserter(unorderedAsserter()).
exercise();
}
@Test
public void testDoubleSingleton() {
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier("[0, 1)", () -> DoubleStream.of(1));
withData(data).
stream(s -> s).
expectedResult(Collections.singletonList(1.0)).
exercise();
withData(data).
stream(s -> s.map(i -> i)).
expectedResult(Collections.singletonList(1.0)).
exercise();
}
private void testDoubleStreamBuilder(int size, Function<Integer, DoubleStream> supplier) {
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier(String.format("[0, %d)", size),
() -> supplier.apply(size));
withData(data).
stream(s -> s).
expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise();
withData(data).
stream(s -> s.map(i -> i)).
expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise();
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testOps(String name, TestData.OfDouble data) {
AtomicLong expectedCount = new AtomicLong();
data.stream().forEach(e -> expectedCount.incrementAndGet());
withData(data).
terminal(DoubleStream::count).
expectedResult(expectedCount.get()).
exercise();
}
private TestData.OfDouble doubles() {
return doubleRange(0, 1L << 53);
}
private TestData.OfDouble doubleRange(long l, long u) {
return TestData.Factory.ofDoubleSupplier(
String.format("[%d, %d)", l, u),
() -> LongStream.range(l, u).mapToDouble(i -> (double) i));
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleParSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.parallelStream()).spliterator());
}
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.stream()).spliterator());
}
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleParSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.parallelStream()).spliterator());
}
}
private TestData.OfDouble doubles() {
return doubleRange(0, 1L << 53);
}
private TestData.OfDouble doubleRange(long l, long u) {
return TestData.Factory.ofDoubleSupplier(
String.format("[%d, %d)", l, u),
() -> LongStream.range(l, u).mapToDouble(i -> (double) i));
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.stream()).spliterator());
}
}