diff options
Diffstat (limited to 'src/test/java/au/id/zancanaro/javacheck/OptionalFunctorRulesTest.java')
-rw-r--r-- | src/test/java/au/id/zancanaro/javacheck/OptionalFunctorRulesTest.java | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/src/test/java/au/id/zancanaro/javacheck/OptionalFunctorRulesTest.java b/src/test/java/au/id/zancanaro/javacheck/OptionalFunctorRulesTest.java deleted file mode 100644 index 5ef552e..0000000 --- a/src/test/java/au/id/zancanaro/javacheck/OptionalFunctorRulesTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package au.id.zancanaro.javacheck; - -import au.id.zancanaro.javacheck.annotations.DataSource; -import au.id.zancanaro.javacheck.annotations.Property; -import au.id.zancanaro.javacheck.junit.Properties; -import org.junit.runner.RunWith; - -import java.util.Optional; -import java.util.function.Function; - -import static au.id.zancanaro.javacheck.Generator.pure; -import static au.id.zancanaro.javacheck.Generators.integer; -import static au.id.zancanaro.javacheck.Generators.oneOf; -import static org.junit.Assert.assertEquals; - -@RunWith(Properties.class) -public class OptionalFunctorRulesTest { - - @DataSource - public static Generator<Optional<Integer>> listOfIntegers = oneOf( - pure(Optional.empty()), - integer().map(Optional::of)); - - @DataSource - public static Generator<Function<Integer, Integer>> integerFunction = - oneOf( - integer().map(OptionalFunctorRulesTest::plusI), - integer().map(OptionalFunctorRulesTest::timesI), - integer().map(OptionalFunctorRulesTest::constantlyI)); - - @Property - public void mappingCompositionsWithStreams( - Optional<Integer> optional, - Function<Integer, Integer> f, - Function<Integer, Integer> g) { - Optional<Integer> left = optional - .map(g) - .map(f); - - Optional<Integer> right = optional - .map(x -> f.apply(g.apply(x))); - - assertEquals(left, right); - } - - @Property - public void mappingCompositionsWithIntermediateList( - Optional<Integer> optional, - Function<Integer, Integer> f, - Function<Integer, Integer> g) { - Optional<Integer> intermediate = optional.map(g); - Optional<Integer> left = intermediate.map(f); - - Optional<Integer> right = optional - .map(x -> f.apply(g.apply(x))); - - assertEquals(left, right); - } - - @Property - public void mapIdentityIsIdentity(Optional<Integer> optional) { - Optional<Integer> mapped = optional.map(x -> x); - - assertEquals(optional, mapped); - } - - private static Function<Integer,Integer> plusI(final int i) { - return new Function<Integer, Integer>() { - @Override - public Integer apply(Integer integer) { - return i + integer; - } - - @Override - public String toString() { - return "x -> x + " + i; - } - }; - } - - private static Function<Integer,Integer> timesI(final int i) { - return new Function<Integer, Integer>() { - @Override - public Integer apply(Integer integer) { - return i * integer; - } - - @Override - public String toString() { - return "x -> x * " + i; - } - }; - } - private static Function<Integer,Integer> constantlyI(final int i) { - return new Function<Integer, Integer>() { - @Override - public Integer apply(Integer integer) { - return i; - } - - @Override - public String toString() { - return "x -> " + i; - } - }; - } -} |