summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/junit
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-01 11:41:16 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-01 11:41:16 +1000
commit8187f024bae57267af514c5dcb730de09e573e41 (patch)
treecba17e2e770de4972f57b60cdd443248fd68c458 /src/test/java/au/id/zancanaro/javacheck/junit
parentedfce37bc21699042baf14ad6d172d3187fe530c (diff)
Move packages, make lists shrink in size, generate lists instead of arrays as the 'primitive' operation (issues with generics)
Diffstat (limited to 'src/test/java/au/id/zancanaro/javacheck/junit')
-rw-r--r--src/test/java/au/id/zancanaro/javacheck/junit/SimpleListOperationsTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/au/id/zancanaro/javacheck/junit/SimpleListOperationsTest.java b/src/test/java/au/id/zancanaro/javacheck/junit/SimpleListOperationsTest.java
new file mode 100644
index 0000000..8a298be
--- /dev/null
+++ b/src/test/java/au/id/zancanaro/javacheck/junit/SimpleListOperationsTest.java
@@ -0,0 +1,45 @@
+package au.id.zancanaro.javacheck.junit;
+
+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;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static au.id.zancanaro.javacheck.Generators.*;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Properties.class)
+public class SimpleListOperationsTest {
+
+ @DataSource
+ public static Generator<List<Integer>> listOfIntegers = listOf(integer());
+
+ @DataSource
+ public static Generator<List<String>> listOfStrings = listOf(stringOf(alphaNumericCharacter()));
+
+ @Property(maxSize = 100, runs = 1000)
+ 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);
+
+ assertEquals(left, right);
+ }
+
+ @Property(maxSize = 100, runs = 1000)
+ public void reverseIsItsOwnInverse(List<String> list) {
+ List<String> reversed = new ArrayList<>(list);
+ Collections.reverse(reversed);
+ Collections.reverse(reversed);
+
+ assertEquals(list, reversed);
+ }
+}