@Test public void works_with_a_single_type() { final Stream<Integer> stream = Streams.of(6, 3, 2, 7); assertThat(stream.foldLeft(summation(), 0), is(18)); }
@Test public void works_with_multiple_types() { final Stream<Integer> stream = Streams.of(6, 3, 2, 7); assertThat(stream.foldLeft(joinAsString(), ""), is(", 6, 3, 2, 7")); }
@Test public void retains_order() { final Stream<Integer> stream = Streams.of(3, 2, 1); assertThat(stream.toList(), contains(3, 2, 1)); }
@Test public void retains_duplicates() { final Stream<Integer> stream = Streams.of(2, 3, 2, 1); assertThat(stream.toList(), contains(2, 3, 2, 1)); }
@Test public void strips_duplicates_out_of_a_stream() { final Stream<Integer> stream = Streams.of(7, 2, 5, 7, 7, 9, 4, 5, 2); assertThat(stream.unique(), contains(7, 2, 5, 9, 4)); }
@Test public void converts_a_stream_to_an_equivalent_list() { final Stream<Integer> stream = Streams.of(1, 2, 3); assertThat(stream.toList(), contains(1, 2, 3)); }
@Test public void makes_no_changes_to_an_already_unique_stream() { final Stream<Integer> stream = Streams.of(7, 2, 5, 9, 4); assertThat(stream.unique(), contains(7, 2, 5, 9, 4)); }
@Test public void is_lazy() { final Stream<Object> stream = Streams.wrap(new ThrowingIterator()); stream.unique(); }
@Override public Stream<T> determineTail() { return !one.isEmpty() ? new Concat<T>(one.tail(), two) : two.tail(); }
@Override public T determineHead() { return !one.isEmpty() ? one.head() : two.head(); }
@Override public boolean determineIsEmpty() { return one.isEmpty() && two.isEmpty(); }