package l8er;

import static com.googlecode.totallylazy.Sequences.sequence;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.googlecode.totallylazy.Callable1;
import com.googlecode.totallylazy.Callable2;
import com.googlecode.totallylazy.Predicate;

public class TotallyLazy {

	private static final Predicate<Integer> even = new Predicate<Integer>() {
		@Override public boolean matches(final Integer n) {
			return (n & 1) != 1;
		}
	};

	private static final Predicate<Integer> odd = new Predicate<Integer>() {
		@Override public boolean matches(final Integer n) {
			return !even.matches(n);
		}
	};

	private static final Callable1<Integer, String> toString = new Callable1<Integer, String>() {
		@Override public String call(final Integer n) throws Exception {
			return String.valueOf(n);
		}
	};

	private static final Callable2<Integer, Integer, Integer> sum = new Callable2<Integer, Integer, Integer>() {
		@Override public Integer call(final Integer n, final Integer m) throws Exception {
			return n + m;
		}
	};

	private static final Callable2<Integer, Integer, Integer> add = sum;

	@Test
	public void evenTest() {
		assertFalse(even.matches(7));
		assertTrue(even.matches(14));
		assertTrue(odd.matches(7));
		assertFalse(odd.matches(14));
	}

	@Test
	public void examples() {
		sequence(1, 2, 3, 4).filter(even); // lazily returns 2,4
		sequence(1, 2).map(toString); // lazily returns "1", "2"
		sequence(1, 2).mapConcurrently(toString); // lazily distributes the work to background threads
		sequence(1, 2, 3).take(2); // lazily returns 1,2
		sequence(1, 2, 3).drop(2); // lazily returns 3
		sequence(1, 2, 3).tail(); // lazily returns 2,3
		sequence(1, 2, 3).head(); // eagerly returns 1
		sequence(1, 2, 3).reduce(sum); // eagerly return 6
		sequence(1, 3, 5).find(even); // eagerly returns none()
		sequence(1, 2, 3).contains(2); // eagerly returns true
		sequence(1, 2, 3).exists(even); // eagerly return true
		sequence(1, 2, 3).forAll(odd); // eagerly returns false;
		sequence(1, 2, 3).foldLeft(0, add); // eagerly returns 6
		sequence(1, 2, 3).toString(); // eagerly returns "1,2,3"
		sequence(1, 2, 3).toString(":"); // eagerly returns "1:2:3"

	}
}

@@ -53,70 +53,206 @@
 azy.
-Sequences.sequence;%0Aimport static org.junit.Assert.assertFalse
+Option.none;%0Aimport static com.googlecode.totallylazy.Sequences.sequence;%0Aimport static org.hamcrest.core.Is.is;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertThat
 ;%0Aim
@@ -1498,16 +1498,27 @@
 s() %7B%0A%09%09
+assertThat(
 sequence
@@ -1546,389 +1546,418 @@
 ven)
-; // lazily returns 2,4%0A%09%09sequence(1, 2).map(toString); // lazily returns %221%22, %222%22%0A%09%09sequence(1, 2).mapConcurrently(toString); // lazily distributes the work to background threads%0A%09%09sequence(1, 2, 3).take(2); // lazily returns 1,2%0A%09%09sequence(1, 2, 3).drop(2); // lazily returns 3%0A%09%09sequence(1, 2, 3).tail(); // lazily returns 2,3%0A%09%09sequence(1, 2, 3).head(); // eagerly returns 1%0A%09%09
+, is(sequence(2, 4)));%0A%09%09assertThat(sequence(1, 2).map(toString), is(sequence(%221%22, %222%22)));%0A%09%09assertThat(sequence(1, 2).mapConcurrently(toString), is(sequence(%221%22, %222%22)));%0A%09%09assertThat(sequence(1, 2, 3).take(2), is(sequence(1, 2)));%0A%09%09assertThat(sequence(1, 2, 3).drop(2), is(sequence(3)));%0A%09%09assertThat(sequence(1, 2, 3).tail(), is(sequence(2, 3)));%0A%09%09assertThat(sequence(1, 2, 3).head(), is(1));%0A%09%09assertThat(
 sequ
@@ -1985,32 +1985,31 @@
 sum)
-; // eagerly return 6%0A%09%09
+, is(6));%0A%09%09assertThat(
 sequ
@@ -2036,38 +2036,36 @@
 ven)
-; // eagerly returns none()%0A%09%09
+, is(none()));%0A%09%09assertTrue(
 sequ
@@ -2093,36 +2093,24 @@
 s(2)
-; // eagerly returns true%0A%09%09
+);%0A%09%09assertTrue(
 sequ
@@ -2139,35 +2139,25 @@
 ven)
-; // eagerly return true%0A%09%09
+);%0A%09%09assertFalse(
 sequ
@@ -2185,38 +2185,24 @@
 odd)
-; // eagerly returns false;%0A%09%09
+);%0A%09%09assertThat(
 sequ
@@ -2235,33 +2235,31 @@
 add)
-; // eagerly returns 6%0A%09%09
+, is(6));%0A%09%09assertThat(
 sequ
@@ -2286,39 +2286,37 @@
 ng()
-; // eagerly returns %221,2,3%22%0A%09%09
+, is(%221,2,3%22));%0A%09%09assertThat(
 sequ
@@ -2346,36 +2346,23 @@
 %22:%22)
-; // eagerly returns 
+, is(
 %221:2:3%22
+));
 %0A%0A%09%7D

Make comments to asserts