From a4b5a5f904fe9f21697cd8fc8998c7e6e86306af Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sun, 31 May 2015 23:47:38 +1000 Subject: 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 --- src/test/java/au/id/zancanaro/PropertyTests.java | 43 ++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'src/test') 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 gen = Generators.integer(); + public static Generator> 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 list) { + List left = new ArrayList<>(list); + Collections.sort(left); + + List right = new ArrayList<>(list); + Collections.sort(right); + Collections.sort(right); + + Assert.assertEquals(left, right); + } + + @Property + public void reverseIsItsOwnInverse(List list) { + List reversed = new ArrayList<>(list); + Collections.reverse(reversed); + Collections.reverse(reversed); + + Assert.assertEquals(list, reversed); } } -- cgit v1.2.3