public void testMap() { SpliteratorTester.of( () -> CollectSpliterators.map( Arrays.spliterator(new String[] {"a", "b", "c", "d", "e"}), Ascii::toUpperCase)) .expect("A", "B", "C", "D", "E"); }
public void testFlatMap() { SpliteratorTester.of( () -> CollectSpliterators.flatMap( Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}), (String str) -> Lists.charactersOf(str).spliterator(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.NONNULL, 7)) .expect('a', 'b', 'c', 'd', 'e', 'f', 'g'); }
public void testConcat_refStream() { assertThat(Streams.concat(Stream.of("a"), Stream.of("b"), Stream.empty(), Stream.of("c", "d"))) .containsExactly("a", "b", "c", "d") .inOrder(); SpliteratorTester.of( () -> Streams.concat(Stream.of("a"), Stream.of("b"), Stream.empty(), Stream.of("c", "d")) .spliterator()) .expect("a", "b", "c", "d"); }
private void testMapWithIndex(Function<Collection<String>, Stream<String>> collectionImpl) { SpliteratorTester.of( () -> Streams.mapWithIndex( collectionImpl.apply(ImmutableList.of()), (str, i) -> str + ":" + i) .spliterator()) .expect(ImmutableList.of()); SpliteratorTester.of( () -> Streams.mapWithIndex( collectionImpl.apply(ImmutableList.of("a", "b", "c", "d", "e")), (str, i) -> str + ":" + i) .spliterator()) .expect("a:0", "b:1", "c:2", "d:3", "e:4"); }
@GwtIncompatible // TODO(b/38490623): reenable after GWT double-to-string conversion is fixed public void testMapWithIndex_doubleStream() { SpliteratorTester.of( () -> Streams.mapWithIndex(DoubleStream.of(0, 1, 2), (x, i) -> x + ":" + i).spliterator()) .expect("0.0:0", "1.0:1", "2.0:2"); }
@CollectionFeature.Require(absent = KNOWN_ORDER) public void testSpliteratorUnknownOrder() { synchronized (collection) { SpliteratorTester.of(collection::spliterator).expect(getSampleElements()); } }
@CollectionFeature.Require(KNOWN_ORDER) public void testSpliteratorKnownOrder() { synchronized (collection) { SpliteratorTester.of(collection::spliterator).expect(getOrderedElements()).inOrder(); } }
public void testMapWithIndex_intStream() { SpliteratorTester.of( () -> Streams.mapWithIndex(IntStream.of(0, 1, 2), (x, i) -> x + ":" + i).spliterator()) .expect("0:0", "1:1", "2:2"); }
public void testMapWithIndex_longStream() { SpliteratorTester.of( () -> Streams.mapWithIndex(LongStream.of(0, 1, 2), (x, i) -> x + ":" + i).spliterator()) .expect("0:0", "1:1", "2:2"); }
public void testMapWithIndex_doubleStream() { SpliteratorTester.of( () -> Streams.mapWithIndex(DoubleStream.of(0, 1, 2), (x, i) -> x + ":" + i).spliterator()) .expect("0.0:0", "1.0:1", "2.0:2"); }