265 for (boolean proxyEstimateSize : new boolean[] {false, true}) { 266 setContext("proxyEstimateSize", proxyEstimateSize); 267 Spliterator<Integer> sp = intermediateOp.apply(l.stream()).spliterator(); 268 ProxyNoExactSizeSpliterator<Integer> psp = new ProxyNoExactSizeSpliterator<>(sp, proxyEstimateSize); 269 Stream<Integer> s = StreamSupport.stream(psp, true); 270 terminalOp.accept(s); 271 Assert.assertTrue(psp.splits > 0, 272 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 273 proxyEstimateSize)); 274 Assert.assertTrue(psp.prefixSplits > 0, 275 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 276 proxyEstimateSize)); 277 Assert.assertTrue(psp.sizeOnTraversal < l.size(), 278 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 279 l.size(), proxyEstimateSize)); 280 } 281 } 282 } 283 } 284 285 @Test(dataProvider = "StreamTestData<Integer>", 286 dataProviderClass = StreamTestDataProvider.class, 287 groups = { "serialization-hostile" }) 288 public void testStreamSpliterators(String name, TestData.OfRef<Integer> data) { 289 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 290 withData(data). 291 stream((Stream<Integer> in) -> { 292 Stream<Integer> out = f.apply(in); 293 return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 294 }). 295 exercise(); 296 297 withData(data). 298 stream((Stream<Integer> in) -> { 299 Stream<Integer> out = f.apply(in); 300 return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 301 }). 302 exercise(); 303 } 304 } 305 306 @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 307 public void testSpliterators(String name, TestData.OfRef<Integer> data) { 308 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 309 SpliteratorTestHelper.testSpliterator(() -> f.apply(data.stream()).spliterator()); 310 } 311 } 312 313 @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class) 314 public void testParSpliterators(String name, TestData.OfRef<Integer> data) { 315 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 316 SpliteratorTestHelper.testSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 317 } 318 } 319 320 private List<Function<Stream<Integer>, Stream<Integer>>> streamFunctions; 321 322 List<Function<Stream<Integer>, Stream<Integer>>> streamFunctions() { 323 if (streamFunctions == null) { 324 List<Function<Stream<Integer>, Stream<Integer>>> opFunctions = Arrays.asList( 325 s -> s.filter(pEven), 326 s -> s.map(mDoubler), 327 // @@@ Add distinct once asserting results with or without order 328 // is correctly supported 329 // s -> s.distinct(), 330 s -> s.sorted()); 331 332 streamFunctions = permuteStreamFunctions(opFunctions); 333 } 334 335 return streamFunctions; 336 } 337 338 // 339 340 public void testIntSplitting() { 341 List<Consumer<IntStream>> terminalOps = Arrays.asList( 342 s -> s.toArray(), 343 s -> s.forEach(e -> {}), 344 s -> s.reduce(Integer::sum) 345 ); 346 361 // Size is assumed to be larger than the target size for no splitting 362 // @@@ Need way to obtain the target size 363 Spliterator.OfInt sp = intermediateOp.apply(IntStream.range(0, 1000)).spliterator(); 364 ProxyNoExactSizeSpliterator.OfInt psp = new ProxyNoExactSizeSpliterator.OfInt(sp, proxyEstimateSize); 365 IntStream s = StreamSupport.intStream(psp, true); 366 terminalOp.accept(s); 367 Assert.assertTrue(psp.splits > 0, 368 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 369 proxyEstimateSize)); 370 Assert.assertTrue(psp.prefixSplits > 0, 371 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 372 proxyEstimateSize)); 373 Assert.assertTrue(psp.sizeOnTraversal < 1000, 374 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 375 1000, proxyEstimateSize)); 376 } 377 } 378 } 379 } 380 381 @Test(dataProvider = "IntStreamTestData", 382 dataProviderClass = IntStreamTestDataProvider.class, 383 groups = { "serialization-hostile" }) 384 public void testIntStreamSpliterators(String name, TestData.OfInt data) { 385 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 386 withData(data). 387 stream(in -> { 388 IntStream out = f.apply(in); 389 return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 390 }). 391 exercise(); 392 393 withData(data). 394 stream((in) -> { 395 IntStream out = f.apply(in); 396 return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 397 }). 398 exercise(); 399 } 400 } 401 402 @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 403 public void testIntSpliterators(String name, TestData.OfInt data) { 404 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 405 SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.stream()).spliterator()); 406 } 407 } 408 409 @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) 410 public void testIntParSpliterators(String name, TestData.OfInt data) { 411 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 412 SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 413 } 414 } 415 416 private List<Function<IntStream, IntStream>> intStreamFunctions; 417 418 List<Function<IntStream, IntStream>> intStreamFunctions() { 419 if (intStreamFunctions == null) { 420 List<Function<IntStream, IntStream>> opFunctions = Arrays.asList( 421 s -> s.filter(ipEven), 422 s -> s.map(irDoubler), 423 s -> s.sorted()); 424 425 intStreamFunctions = permuteStreamFunctions(opFunctions); 426 } 427 428 return intStreamFunctions; 429 } 430 431 // 432 433 public void testLongSplitting() { 434 List<Consumer<LongStream>> terminalOps = Arrays.asList( 435 s -> s.toArray(), 436 s -> s.forEach(e -> {}), 437 s -> s.reduce(Long::sum) 438 ); 439 440 List<UnaryOperator<LongStream>> intermediateOps = Arrays.asList( 441 s -> s.parallel(), 442 // The following ensures the wrapping spliterator is tested 454 // Size is assumed to be larger than the target size for no splitting 455 // @@@ Need way to obtain the target size 456 Spliterator.OfLong sp = intermediateOp.apply(LongStream.range(0, 1000)).spliterator(); 457 ProxyNoExactSizeSpliterator.OfLong psp = new ProxyNoExactSizeSpliterator.OfLong(sp, proxyEstimateSize); 458 LongStream s = StreamSupport.longStream(psp, true); 459 terminalOp.accept(s); 460 Assert.assertTrue(psp.splits > 0, 461 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 462 proxyEstimateSize)); 463 Assert.assertTrue(psp.prefixSplits > 0, 464 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 465 proxyEstimateSize)); 466 Assert.assertTrue(psp.sizeOnTraversal < 1000, 467 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 468 1000, proxyEstimateSize)); 469 } 470 } 471 } 472 } 473 474 @Test(dataProvider = "LongStreamTestData", 475 dataProviderClass = LongStreamTestDataProvider.class, 476 groups = { "serialization-hostile" }) 477 public void testLongStreamSpliterators(String name, TestData.OfLong data) { 478 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 479 withData(data). 480 stream(in -> { 481 LongStream out = f.apply(in); 482 return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 483 }). 484 exercise(); 485 486 withData(data). 487 stream((in) -> { 488 LongStream out = f.apply(in); 489 return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 490 }). 491 exercise(); 492 } 493 } 494 495 @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 496 public void testLongSpliterators(String name, TestData.OfLong data) { 497 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 498 SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.stream()).spliterator()); 499 } 500 } 501 502 @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) 503 public void testLongParSpliterators(String name, TestData.OfLong data) { 504 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 505 SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 506 } 507 } 508 509 private List<Function<LongStream, LongStream>> longStreamFunctions; 510 511 List<Function<LongStream, LongStream>> longStreamFunctions() { 512 if (longStreamFunctions == null) { 513 List<Function<LongStream, LongStream>> opFunctions = Arrays.asList( 514 s -> s.filter(lpEven), 515 s -> s.map(x -> x * 2L), 516 s -> s.sorted()); 517 518 longStreamFunctions = permuteStreamFunctions(opFunctions); 519 } 520 521 return longStreamFunctions; 522 } 523 524 // 525 526 public void testDoubleSplitting() { 527 List<Consumer<DoubleStream>> terminalOps = Arrays.asList( 528 s -> s.toArray(), 529 s -> s.forEach(e -> {}), 530 s -> s.reduce(Double::sum) 531 ); 532 533 List<UnaryOperator<DoubleStream>> intermediateOps = Arrays.asList( 534 s -> s.parallel(), 535 // The following ensures the wrapping spliterator is tested 547 // Size is assumed to be larger than the target size for no splitting 548 // @@@ Need way to obtain the target size 549 Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).asDoubleStream()).spliterator(); 550 ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize); 551 DoubleStream s = StreamSupport.doubleStream(psp, true); 552 terminalOp.accept(s); 553 Assert.assertTrue(psp.splits > 0, 554 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 555 proxyEstimateSize)); 556 Assert.assertTrue(psp.prefixSplits > 0, 557 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 558 proxyEstimateSize)); 559 Assert.assertTrue(psp.sizeOnTraversal < 1000, 560 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 561 1000, proxyEstimateSize)); 562 } 563 } 564 } 565 } 566 567 @Test(dataProvider = "DoubleStreamTestData", 568 dataProviderClass = DoubleStreamTestDataProvider.class, 569 groups = { "serialization-hostile" }) 570 public void testDoubleStreamSpliterators(String name, TestData.OfDouble data) { 571 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 572 withData(data). 573 stream(in -> { 574 DoubleStream out = f.apply(in); 575 return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 576 }). 577 exercise(); 578 579 withData(data). 580 stream((in) -> { 581 DoubleStream out = f.apply(in); 582 return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 583 }). 584 exercise(); 585 } 586 } 587 588 @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 589 public void testDoubleSpliterators(String name, TestData.OfDouble data) { 590 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 591 SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.stream()).spliterator()); 592 } 593 } 594 595 @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) 596 public void testDoubleParSpliterators(String name, TestData.OfDouble data) { 597 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 598 SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 599 } 600 } 601 602 private List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions; 603 604 List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions() { 605 if (doubleStreamFunctions == null) { 606 List<Function<DoubleStream, DoubleStream>> opFunctions = Arrays.asList( 607 s -> s.filter(dpEven), 608 s -> s.map(x -> x * 2.0), 609 s -> s.sorted()); 610 611 doubleStreamFunctions = permuteStreamFunctions(opFunctions); 612 } 613 614 return doubleStreamFunctions; 615 } 616 } | 265 for (boolean proxyEstimateSize : new boolean[] {false, true}) { 266 setContext("proxyEstimateSize", proxyEstimateSize); 267 Spliterator<Integer> sp = intermediateOp.apply(l.stream()).spliterator(); 268 ProxyNoExactSizeSpliterator<Integer> psp = new ProxyNoExactSizeSpliterator<>(sp, proxyEstimateSize); 269 Stream<Integer> s = StreamSupport.stream(psp, true); 270 terminalOp.accept(s); 271 Assert.assertTrue(psp.splits > 0, 272 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 273 proxyEstimateSize)); 274 Assert.assertTrue(psp.prefixSplits > 0, 275 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 276 proxyEstimateSize)); 277 Assert.assertTrue(psp.sizeOnTraversal < l.size(), 278 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 279 l.size(), proxyEstimateSize)); 280 } 281 } 282 } 283 } 284 285 @Test(dataProvider = "StreamTestData<Integer>.small", 286 dataProviderClass = StreamTestDataProvider.class, 287 groups = { "serialization-hostile" }) 288 public void testStreamSpliterators(String name, TestData.OfRef<Integer> data) { 289 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 290 withData(data). 291 stream((Stream<Integer> in) -> { 292 Stream<Integer> out = f.apply(in); 293 return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 294 }). 295 exercise(); 296 297 withData(data). 298 stream((Stream<Integer> in) -> { 299 Stream<Integer> out = f.apply(in); 300 return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 301 }). 302 exercise(); 303 } 304 } 305 306 @Test(dataProvider = "StreamTestData<Integer>.small", dataProviderClass = StreamTestDataProvider.class) 307 public void testSpliterators(String name, TestData.OfRef<Integer> data) { 308 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 309 SpliteratorTestHelper.testSpliterator(() -> f.apply(data.stream()).spliterator()); 310 } 311 } 312 313 @Test(dataProvider = "StreamTestData<Integer>.small", dataProviderClass = StreamTestDataProvider.class) 314 public void testParSpliterators(String name, TestData.OfRef<Integer> data) { 315 for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) { 316 SpliteratorTestHelper.testSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 317 } 318 } 319 320 private List<Function<Stream<Integer>, Stream<Integer>>> streamFunctions; 321 322 List<Function<Stream<Integer>, Stream<Integer>>> streamFunctions() { 323 if (streamFunctions == null) { 324 List<Function<Stream<Integer>, Stream<Integer>>> opFunctions = Arrays.asList( 325 s -> s.filter(pEven), 326 s -> s.flatMap(x -> Stream.of(x, x)), 327 // @@@ Add distinct once asserting results with or without order 328 // is correctly supported 329 // s -> s.distinct(), 330 s -> s.sorted()); 331 332 streamFunctions = permuteStreamFunctions(opFunctions); 333 } 334 335 return streamFunctions; 336 } 337 338 // 339 340 public void testIntSplitting() { 341 List<Consumer<IntStream>> terminalOps = Arrays.asList( 342 s -> s.toArray(), 343 s -> s.forEach(e -> {}), 344 s -> s.reduce(Integer::sum) 345 ); 346 361 // Size is assumed to be larger than the target size for no splitting 362 // @@@ Need way to obtain the target size 363 Spliterator.OfInt sp = intermediateOp.apply(IntStream.range(0, 1000)).spliterator(); 364 ProxyNoExactSizeSpliterator.OfInt psp = new ProxyNoExactSizeSpliterator.OfInt(sp, proxyEstimateSize); 365 IntStream s = StreamSupport.intStream(psp, true); 366 terminalOp.accept(s); 367 Assert.assertTrue(psp.splits > 0, 368 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 369 proxyEstimateSize)); 370 Assert.assertTrue(psp.prefixSplits > 0, 371 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 372 proxyEstimateSize)); 373 Assert.assertTrue(psp.sizeOnTraversal < 1000, 374 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 375 1000, proxyEstimateSize)); 376 } 377 } 378 } 379 } 380 381 @Test(dataProvider = "IntStreamTestData.small", 382 dataProviderClass = IntStreamTestDataProvider.class, 383 groups = { "serialization-hostile" }) 384 public void testIntStreamSpliterators(String name, TestData.OfInt data) { 385 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 386 withData(data). 387 stream(in -> { 388 IntStream out = f.apply(in); 389 return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 390 }). 391 exercise(); 392 393 withData(data). 394 stream((in) -> { 395 IntStream out = f.apply(in); 396 return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 397 }). 398 exercise(); 399 } 400 } 401 402 @Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class) 403 public void testIntSpliterators(String name, TestData.OfInt data) { 404 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 405 SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.stream()).spliterator()); 406 } 407 } 408 409 @Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class) 410 public void testIntParSpliterators(String name, TestData.OfInt data) { 411 for (Function<IntStream, IntStream> f : intStreamFunctions()) { 412 SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 413 } 414 } 415 416 private List<Function<IntStream, IntStream>> intStreamFunctions; 417 418 List<Function<IntStream, IntStream>> intStreamFunctions() { 419 if (intStreamFunctions == null) { 420 List<Function<IntStream, IntStream>> opFunctions = Arrays.asList( 421 s -> s.filter(ipEven), 422 s -> s.flatMap(x -> IntStream.of(x, x)), 423 s -> s.sorted()); 424 425 intStreamFunctions = permuteStreamFunctions(opFunctions); 426 } 427 428 return intStreamFunctions; 429 } 430 431 // 432 433 public void testLongSplitting() { 434 List<Consumer<LongStream>> terminalOps = Arrays.asList( 435 s -> s.toArray(), 436 s -> s.forEach(e -> {}), 437 s -> s.reduce(Long::sum) 438 ); 439 440 List<UnaryOperator<LongStream>> intermediateOps = Arrays.asList( 441 s -> s.parallel(), 442 // The following ensures the wrapping spliterator is tested 454 // Size is assumed to be larger than the target size for no splitting 455 // @@@ Need way to obtain the target size 456 Spliterator.OfLong sp = intermediateOp.apply(LongStream.range(0, 1000)).spliterator(); 457 ProxyNoExactSizeSpliterator.OfLong psp = new ProxyNoExactSizeSpliterator.OfLong(sp, proxyEstimateSize); 458 LongStream s = StreamSupport.longStream(psp, true); 459 terminalOp.accept(s); 460 Assert.assertTrue(psp.splits > 0, 461 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 462 proxyEstimateSize)); 463 Assert.assertTrue(psp.prefixSplits > 0, 464 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 465 proxyEstimateSize)); 466 Assert.assertTrue(psp.sizeOnTraversal < 1000, 467 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 468 1000, proxyEstimateSize)); 469 } 470 } 471 } 472 } 473 474 @Test(dataProvider = "LongStreamTestData.small", 475 dataProviderClass = LongStreamTestDataProvider.class, 476 groups = { "serialization-hostile" }) 477 public void testLongStreamSpliterators(String name, TestData.OfLong data) { 478 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 479 withData(data). 480 stream(in -> { 481 LongStream out = f.apply(in); 482 return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 483 }). 484 exercise(); 485 486 withData(data). 487 stream((in) -> { 488 LongStream out = f.apply(in); 489 return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 490 }). 491 exercise(); 492 } 493 } 494 495 @Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class) 496 public void testLongSpliterators(String name, TestData.OfLong data) { 497 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 498 SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.stream()).spliterator()); 499 } 500 } 501 502 @Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class) 503 public void testLongParSpliterators(String name, TestData.OfLong data) { 504 for (Function<LongStream, LongStream> f : longStreamFunctions()) { 505 SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 506 } 507 } 508 509 private List<Function<LongStream, LongStream>> longStreamFunctions; 510 511 List<Function<LongStream, LongStream>> longStreamFunctions() { 512 if (longStreamFunctions == null) { 513 List<Function<LongStream, LongStream>> opFunctions = Arrays.asList( 514 s -> s.filter(lpEven), 515 s -> s.flatMap(x -> LongStream.of(x, x)), 516 s -> s.sorted()); 517 518 longStreamFunctions = permuteStreamFunctions(opFunctions); 519 } 520 521 return longStreamFunctions; 522 } 523 524 // 525 526 public void testDoubleSplitting() { 527 List<Consumer<DoubleStream>> terminalOps = Arrays.asList( 528 s -> s.toArray(), 529 s -> s.forEach(e -> {}), 530 s -> s.reduce(Double::sum) 531 ); 532 533 List<UnaryOperator<DoubleStream>> intermediateOps = Arrays.asList( 534 s -> s.parallel(), 535 // The following ensures the wrapping spliterator is tested 547 // Size is assumed to be larger than the target size for no splitting 548 // @@@ Need way to obtain the target size 549 Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).asDoubleStream()).spliterator(); 550 ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize); 551 DoubleStream s = StreamSupport.doubleStream(psp, true); 552 terminalOp.accept(s); 553 Assert.assertTrue(psp.splits > 0, 554 String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", 555 proxyEstimateSize)); 556 Assert.assertTrue(psp.prefixSplits > 0, 557 String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", 558 proxyEstimateSize)); 559 Assert.assertTrue(psp.sizeOnTraversal < 1000, 560 String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 561 1000, proxyEstimateSize)); 562 } 563 } 564 } 565 } 566 567 @Test(dataProvider = "DoubleStreamTestData.small", 568 dataProviderClass = DoubleStreamTestDataProvider.class, 569 groups = { "serialization-hostile" }) 570 public void testDoubleStreamSpliterators(String name, TestData.OfDouble data) { 571 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 572 withData(data). 573 stream(in -> { 574 DoubleStream out = f.apply(in); 575 return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); 576 }). 577 exercise(); 578 579 withData(data). 580 stream((in) -> { 581 DoubleStream out = f.apply(in); 582 return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); 583 }). 584 exercise(); 585 } 586 } 587 588 @Test(dataProvider = "DoubleStreamTestData.small", dataProviderClass = DoubleStreamTestDataProvider.class) 589 public void testDoubleSpliterators(String name, TestData.OfDouble data) { 590 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 591 SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.stream()).spliterator()); 592 } 593 } 594 595 @Test(dataProvider = "DoubleStreamTestData.small", dataProviderClass = DoubleStreamTestDataProvider.class) 596 public void testDoubleParSpliterators(String name, TestData.OfDouble data) { 597 for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) { 598 SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.parallelStream()).spliterator()); 599 } 600 } 601 602 private List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions; 603 604 List<Function<DoubleStream, DoubleStream>> doubleStreamFunctions() { 605 if (doubleStreamFunctions == null) { 606 List<Function<DoubleStream, DoubleStream>> opFunctions = Arrays.asList( 607 s -> s.filter(dpEven), 608 s -> s.flatMap(x -> DoubleStream.of(x, x)), 609 s -> s.sorted()); 610 611 doubleStreamFunctions = permuteStreamFunctions(opFunctions); 612 } 613 614 return doubleStreamFunctions; 615 } 616 } |