Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion props-core/src/test/java/fj/data/ReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import static fj.test.Cogen.cogenInteger;
import static fj.test.Property.prop;
import static fj.test.Property.property;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
Expand All @@ -24,7 +26,6 @@ public void testMap() {
// example taken from http://learnyouahaskell.com/for-a-few-monads-more
int x = Reader.unit((Integer i) -> i + 3).map(i -> i * 5).f(8);
assertTrue(x == 55);
// System.out.println(x); // 55
}

@Test
Expand Down Expand Up @@ -108,6 +109,19 @@ public void testAssociativity() {
PropertyAssert.assertResult(p);
}

@Test
public void testAndThen() {
final int y = Reader.unit((Integer i) -> i * 2).andThen(i -> i + 10).f(10);
assertThat(y, is(30));
}

@Test
public void testBind() {
final int y = Reader.unit((Integer i) -> i * 2)
.bind(a -> Reader.unit(i -> a + i + 11)).f(10);
assertThat(y, is(41));
}

public Gen<Reader<Integer, Integer>> arbReader() {
return Arbitrary.arbReader(cogenInteger, arbInteger);
}
Expand Down
14 changes: 10 additions & 4 deletions props-core/src/test/java/fj/data/WriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import fj.Equal;
import fj.F;
import fj.data.test.PropertyAssert;
import fj.test.Arbitrary;
import fj.P;
import fj.test.Gen;
import fj.test.Property;
import org.junit.Assert;
Expand All @@ -14,7 +13,8 @@
import static fj.test.Cogen.cogenInteger;
import static fj.test.Property.prop;
import static fj.test.Property.property;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
* Created by MarkPerry on 17/12/2014.
Expand Down Expand Up @@ -107,7 +107,13 @@ public void testAssociativity() {
assertResult(p);
}


@Test
public void testUnit() {
Writer<String, String> w = Writer.unit("+").tell("foo").tell("bar");
assertThat(w.run(), is(P.p("foobar", "+")));
assertThat(w.log(), is("foobar"));
assertThat(w.value(), is("+"));
}


}