From e0fc94269698982d937b80ff5fd5b1ef8ef28cf4 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Wed, 3 Jun 2015 19:43:14 +1000 Subject: 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 ShrinkTrees yourself, you just generate smaller s, and the generator framework will re-call your strategy to shrink smaller elements. (So, essentially, ShrinkStrategy.shrink(T obj) returns an Iterator 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. --- .../zancanaro/javacheck/ListFunctorRulesTest.java | 61 +++++++++++----------- .../javacheck/SimpleListOperationsTest.java | 1 - 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'src/test/java') 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> listOfIntegers = listOf(integer()); + public static Generator> listOfIntegers = listOf(longInteger()); @DataSource - public static Generator> integerFunction = + public static Generator> 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 list, - Function f, - Function g) { - List left = list.stream() + List list, + Function f, + Function g) { + List left = list.stream() .map(g) .map(f) .collect(Collectors.toList()); - List right = list.stream() - .map(x -> f.apply(g.apply(x))) + List 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 list, - Function f, - Function g) { - List intermediate = list.stream().map(g).collect(Collectors.toList()); - List left = intermediate.stream().map(f).collect(Collectors.toList()); - - List right = list.stream() - .map(x -> f.apply(g.apply(x))) + List list, + Function f, + Function g) { + List intermediate = list.stream().map(g).collect(Collectors.toList()); + List left = intermediate.stream().map(f).collect(Collectors.toList()); + + List right = list.stream() + .map(f.compose(g)) .collect(Collectors.toList()); assertEquals(left, right); } @Property(maxSize = maxSize, runs = runs) - public void mapIdentityIsIdentity(List list) { - List mapped = list.stream().map(x -> x).collect(Collectors.toList()); + public void mapIdentityIsIdentity(List list) { + List mapped = list.stream().map(x -> x).collect(Collectors.toList()); assertEquals(list, mapped); } - private static Function plusI(final int i) { - return new Function() { + private static Function plusI(final long i) { + return new Function() { @Override - public Integer apply(Integer integer) { + public Long apply(Long integer) { return i + integer; } @@ -81,10 +81,10 @@ public class ListFunctorRulesTest { }; } - private static Function timesI(final int i) { - return new Function() { + private static Function timesI(final long i) { + return new Function() { @Override - public Integer apply(Integer integer) { + public Long apply(Long integer) { return i * integer; } @@ -94,10 +94,11 @@ public class ListFunctorRulesTest { } }; } - private static Function constantlyI(final int i) { - return new Function() { + + private static Function constantlyI(final long i) { + return new Function() { @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; -- cgit v1.2.3