diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-05-31 23:47:38 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-05-31 23:47:38 +1000 |
commit | a4b5a5f904fe9f21697cd8fc8998c7e6e86306af (patch) | |
tree | b5f66d8825219f05c4e1903434a121eb40e48cbe /src/test/java/au/id/zancanaro | |
parent | 199037f9c80afd885f1f536d91b40a8397cd6bf2 (diff) |
Lots more updates
+ add a list generator, and some more number generators.
+ bugfix the assumption checking stuff: if it failed once it would pretty
likely continue to fail!
+ write some simple actualy properties:
- reverse . reverse = id
- sort . sort = sort
Diffstat (limited to 'src/test/java/au/id/zancanaro')
-rw-r--r-- | src/test/java/au/id/zancanaro/PropertyTests.java | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/src/test/java/au/id/zancanaro/PropertyTests.java b/src/test/java/au/id/zancanaro/PropertyTests.java index 374a974..dd595e1 100644 --- a/src/test/java/au/id/zancanaro/PropertyTests.java +++ b/src/test/java/au/id/zancanaro/PropertyTests.java @@ -1,35 +1,58 @@ package au.id.zancanaro; import au.id.zancanaro.annotations.Property; +import au.id.zancanaro.annotations.Seed; +import org.hamcrest.CoreMatchers; import org.junit.*; import org.junit.experimental.theories.DataPoint; +import org.junit.matchers.JUnitMatchers; import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @RunWith(PropertyTestRunner.class) public class PropertyTests { public static Generator<Integer> gen = Generators.integer(); + public static Generator<List<Integer>> list = Generators.listOf(Generators.integer()); - @Test - public void testblah() throws Exception { - Assert.assertEquals(10, 11); - - } - + @Ignore @Property public void aIsNotOdd(int a, int b) { - Assume.assumeFalse(a % 2 == 1); Assert.assertFalse(a % 2 == 1); } + @Ignore @Property public void aIsNotLessThanB(int a, int b) { - Assume.assumeFalse(a < b); Assert.assertFalse(a < b); } + @Ignore @Property public void aPlusBLessThanOneHundred(int a, int b) { - Assert.assertTrue("a plus b is five", a + b == 5); - Assert.assertEquals(a + b, 5); + Assert.assertTrue(a + b < 100); + } + + @Property + public void sortingIsIdempotent(List<Integer> list) { + List<Integer> left = new ArrayList<>(list); + Collections.sort(left); + + List<Integer> right = new ArrayList<>(list); + Collections.sort(right); + Collections.sort(right); + + Assert.assertEquals(left, right); + } + + @Property + public void reverseIsItsOwnInverse(List<Integer> list) { + List<Integer> reversed = new ArrayList<>(list); + Collections.reverse(reversed); + Collections.reverse(reversed); + + Assert.assertEquals(list, reversed); } } |