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 11
11
import static fj .test .Cogen .cogenInteger ;
12
12
import static fj .test .Property .prop ;
13
13
import static fj .test .Property .property ;
14
+ import static org .hamcrest .core .Is .is ;
15
+ import static org .junit .Assert .assertThat ;
14
16
import static org .junit .Assert .assertTrue ;
15
17
16
18
/**
@@ -24,7 +26,6 @@ public void testMap() {
24
26
// example taken from http://learnyouahaskell.com/for-a-few-monads-more
25
27
int x = Reader .unit ((Integer i ) -> i + 3 ).map (i -> i * 5 ).f (8 );
26
28
assertTrue (x == 55 );
27
- // System.out.println(x); // 55
28
29
}
29
30
30
31
@ Test
@@ -108,6 +109,19 @@ public void testAssociativity() {
108
109
PropertyAssert .assertResult (p );
109
110
}
110
111
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
+
111
125
public Gen <Reader <Integer , Integer >> arbReader () {
112
126
return Arbitrary .arbReader (cogenInteger , arbInteger );
113
127
}
Original file line number Diff line number Diff line change 2
2
3
3
import fj .Equal ;
4
4
import fj .F ;
5
- import fj .data .test .PropertyAssert ;
6
- import fj .test .Arbitrary ;
5
+ import fj .P ;
7
6
import fj .test .Gen ;
8
7
import fj .test .Property ;
9
8
import org .junit .Assert ;
14
13
import static fj .test .Cogen .cogenInteger ;
15
14
import static fj .test .Property .prop ;
16
15
import 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 ;
18
18
19
19
/**
20
20
* Created by MarkPerry on 17/12/2014.
@@ -107,7 +107,13 @@ public void testAssociativity() {
107
107
assertResult (p );
108
108
}
109
109
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
+ }
111
117
112
118
113
119
}
You can’t perform that action at this time.
0 commit comments