File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
props-core/src/test/java/fj/data Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1111import static fj .test .Cogen .cogenInteger ;
1212import static fj .test .Property .prop ;
1313import static fj .test .Property .property ;
14+ import static org .hamcrest .core .Is .is ;
15+ import static org .junit .Assert .assertThat ;
1416import static org .junit .Assert .assertTrue ;
1517
1618/**
@@ -24,7 +26,6 @@ public void testMap() {
2426 // example taken from http://learnyouahaskell.com/for-a-few-monads-more
2527 int x = Reader .unit ((Integer i ) -> i + 3 ).map (i -> i * 5 ).f (8 );
2628 assertTrue (x == 55 );
27- // System.out.println(x); // 55
2829 }
2930
3031 @ Test
@@ -108,6 +109,19 @@ public void testAssociativity() {
108109 PropertyAssert .assertResult (p );
109110 }
110111
112+ @ Test
113+ public void testAndThen () {
114+ final int y = Reader .unit ((Integer i ) -> i * 2 ).andThen (i -> i + 10 ).f (10 );
115+ assertThat (y , is (30 ));
116+ }
117+
118+ @ Test
119+ public void testBind () {
120+ final int y = Reader .unit ((Integer i ) -> i * 2 )
121+ .bind (a -> Reader .unit (i -> a + i + 11 )).f (10 );
122+ assertThat (y , is (41 ));
123+ }
124+
111125 public Gen <Reader <Integer , Integer >> arbReader () {
112126 return Arbitrary .arbReader (cogenInteger , arbInteger );
113127 }
Original file line number Diff line number Diff line change 22
33import fj .Equal ;
44import fj .F ;
5- import fj .data .test .PropertyAssert ;
6- import fj .test .Arbitrary ;
5+ import fj .P ;
76import fj .test .Gen ;
87import fj .test .Property ;
98import org .junit .Assert ;
1413import static fj .test .Cogen .cogenInteger ;
1514import static fj .test .Property .prop ;
1615import static fj .test .Property .property ;
17- import static org .junit .Assert .assertTrue ;
16+ import static org .hamcrest .MatcherAssert .assertThat ;
17+ import static org .hamcrest .core .Is .is ;
1818
1919/**
2020 * Created by MarkPerry on 17/12/2014.
@@ -107,7 +107,13 @@ public void testAssociativity() {
107107 assertResult (p );
108108 }
109109
110-
110+ @ Test
111+ public void testUnit () {
112+ Writer <String , String > w = Writer .unit ("+" ).tell ("foo" ).tell ("bar" );
113+ assertThat (w .run (), is (P .p ("foobar" , "+" )));
114+ assertThat (w .log (), is ("foobar" ));
115+ assertThat (w .value (), is ("+" ));
116+ }
111117
112118
113119}
You can’t perform that action at this time.
0 commit comments