diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-03 19:43:14 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-03 19:43:14 +1000 |
commit | e0fc94269698982d937b80ff5fd5b1ef8ef28cf4 (patch) | |
tree | 22c335361971363d6856a59ef0c54242f92e74e1 /src/test/java | |
parent | 7b1a783b749ab04ab8219ef28f9b1abb0ded6ca4 (diff) |
Change shrinking a bit, add more generators, fix some types, moved suchThat
Shrinking is now done using a "ShrinkStrategy". It's pretty similar to what it
used to be in the end, but instead of generating new ShrinkTree<T>s yourself,
you just generate smaller <T>s, and the generator framework will re-call your
strategy to shrink smaller elements. (So, essentially, ShrinkStrategy.shrink(T
obj) returns an Iterator<T> which then has smaller trees calculated from it.)
Added some more generators. In particular: longs and doubles.
Fixed some types, so now Generator.tuple(integer(), string()) will work. Yay!
Move suchThat to Generator, so now integer().suchThat(x -> x < 10) will work
instead of the old Generators.suchThat(x -> x < 10, integer()), which felt a
bit weird.
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/au/id/zancanaro/javacheck/ListFunctorRulesTest.java | 61 | ||||
-rw-r--r-- | src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java | 1 |
2 files changed, 31 insertions, 31 deletions
diff --git a/src/test/java/au/id/zancanaro/javacheck/ListFunctorRulesTest.java b/src/test/java/au/id/zancanaro/javacheck/ListFunctorRulesTest.java index 4e516a2..b757bcd 100644 --- a/src/test/java/au/id/zancanaro/javacheck/ListFunctorRulesTest.java +++ b/src/test/java/au/id/zancanaro/javacheck/ListFunctorRulesTest.java @@ -19,27 +19,27 @@ public class ListFunctorRulesTest { private final static int maxSize = 1000; @DataSource - public static Generator<List<Integer>> listOfIntegers = listOf(integer()); + public static Generator<List<Long>> listOfIntegers = listOf(longInteger()); @DataSource - public static Generator<Function<Integer, Integer>> integerFunction = + public static Generator<Function<Long, Long>> integerFunction = oneOf( - integer().map(ListFunctorRulesTest::plusI), - integer().map(ListFunctorRulesTest::timesI), - integer().map(ListFunctorRulesTest::constantlyI)); + longInteger().map(ListFunctorRulesTest::plusI), + longInteger().map(ListFunctorRulesTest::timesI), + longInteger().map(ListFunctorRulesTest::constantlyI)); @Property(maxSize = maxSize, runs = runs) public void mappingCompositionsWithStreams( - List<Integer> list, - Function<Integer, Integer> f, - Function<Integer, Integer> g) { - List<Integer> left = list.stream() + List<Long> list, + Function<Long, Long> f, + Function<Long, Long> g) { + List<Long> left = list.stream() .map(g) .map(f) .collect(Collectors.toList()); - List<Integer> right = list.stream() - .map(x -> f.apply(g.apply(x))) + List<Long> right = list.stream() + .map(f.compose(g)) .collect(Collectors.toList()); assertEquals(left, right); @@ -47,30 +47,30 @@ public class ListFunctorRulesTest { @Property(maxSize = maxSize, runs = runs) public void mappingCompositionsWithIntermediateList( - List<Integer> list, - Function<Integer, Integer> f, - Function<Integer, Integer> g) { - List<Integer> intermediate = list.stream().map(g).collect(Collectors.toList()); - List<Integer> left = intermediate.stream().map(f).collect(Collectors.toList()); - - List<Integer> right = list.stream() - .map(x -> f.apply(g.apply(x))) + List<Long> list, + Function<Long, Long> f, + Function<Long, Long> g) { + List<Long> intermediate = list.stream().map(g).collect(Collectors.toList()); + List<Long> left = intermediate.stream().map(f).collect(Collectors.toList()); + + List<Long> right = list.stream() + .map(f.compose(g)) .collect(Collectors.toList()); assertEquals(left, right); } @Property(maxSize = maxSize, runs = runs) - public void mapIdentityIsIdentity(List<Integer> list) { - List<Integer> mapped = list.stream().map(x -> x).collect(Collectors.toList()); + public void mapIdentityIsIdentity(List<Long> list) { + List<Long> mapped = list.stream().map(x -> x).collect(Collectors.toList()); assertEquals(list, mapped); } - private static Function<Integer,Integer> plusI(final int i) { - return new Function<Integer, Integer>() { + private static Function<Long, Long> plusI(final long i) { + return new Function<Long, Long>() { @Override - public Integer apply(Integer integer) { + public Long apply(Long integer) { return i + integer; } @@ -81,10 +81,10 @@ public class ListFunctorRulesTest { }; } - private static Function<Integer,Integer> timesI(final int i) { - return new Function<Integer, Integer>() { + private static Function<Long, Long> timesI(final long i) { + return new Function<Long, Long>() { @Override - public Integer apply(Integer integer) { + public Long apply(Long integer) { return i * integer; } @@ -94,10 +94,11 @@ public class ListFunctorRulesTest { } }; } - private static Function<Integer,Integer> constantlyI(final int i) { - return new Function<Integer, Integer>() { + + private static Function<Long, Long> constantlyI(final long i) { + return new Function<Long, Long>() { @Override - public Integer apply(Integer integer) { + public Long apply(Long integer) { return i; } diff --git a/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java b/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java index 972b5b6..8f7b075 100644 --- a/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java +++ b/src/test/java/au/id/zancanaro/javacheck/SimpleListOperationsTest.java @@ -1,6 +1,5 @@ package au.id.zancanaro.javacheck; -import au.id.zancanaro.javacheck.Generator; import au.id.zancanaro.javacheck.annotations.DataSource; import au.id.zancanaro.javacheck.annotations.Property; import au.id.zancanaro.javacheck.junit.Properties; |