Ejemplo n.º 1
0
 @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));
 }
Ejemplo n.º 2
0
 @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"));
 }
Ejemplo n.º 3
0
 @Test
 public void retains_order() {
   final Stream<Integer> stream = Streams.of(3, 2, 1);
   assertThat(stream.toList(), contains(3, 2, 1));
 }
Ejemplo n.º 4
0
 @Test
 public void retains_duplicates() {
   final Stream<Integer> stream = Streams.of(2, 3, 2, 1);
   assertThat(stream.toList(), contains(2, 3, 2, 1));
 }
Ejemplo n.º 5
0
 @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));
 }
Ejemplo n.º 6
0
 @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));
 }
Ejemplo n.º 7
0
 @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));
 }
Ejemplo n.º 8
0
 @Test
 public void is_lazy() {
   final Stream<Object> stream = Streams.wrap(new ThrowingIterator());
   stream.unique();
 }
Ejemplo n.º 9
0
 @Override
 public Stream<T> determineTail() {
   return !one.isEmpty() ? new Concat<T>(one.tail(), two) : two.tail();
 }
Ejemplo n.º 10
0
 @Override
 public T determineHead() {
   return !one.isEmpty() ? one.head() : two.head();
 }
Ejemplo n.º 11
0
 @Override
 public boolean determineIsEmpty() {
   return one.isEmpty() && two.isEmpty();
 }