Skip to content

Commit 9e0a6a1

Browse files
committed
Added simple Reader tests
1 parent e71078e commit 9e0a6a1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package fj.data;
2+
3+
import fj.data.Reader;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertTrue;
8+
9+
/**
10+
* Created by MarkPerry on 4/12/2014.
11+
*
12+
* Examples taken from http://learnyouahaskell.com/for-a-few-monads-more
13+
*/
14+
public class ReaderTest {
15+
16+
@Test
17+
public void testMap() {
18+
int x = Reader.unit((Integer i) -> i + 3).map(i -> i * 5).f(8);
19+
assertTrue(x == 55);
20+
// System.out.println(x); // 55
21+
}
22+
23+
@Test
24+
public void testFlatMap() {
25+
int y = Reader.unit((Integer i) -> i * 2).flatMap(a -> Reader.unit((Integer i) -> i + 10).map(b -> a + b)).f(3);
26+
// System.out.println(y); // 19
27+
assertTrue(y == 19);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)