From 89311a86fe73b8f70fe3fb389ed203220fa99ae8 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 16 Jun 2017 20:55:03 +0200 Subject: [PATCH] slowCheck: try shrinking ints to 0 --- slowCheck/src/slowCheck/StructureNode.java | 3 +++ slowCheck/test/slowCheck/GeneratorTest.java | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/slowCheck/src/slowCheck/StructureNode.java b/slowCheck/src/slowCheck/StructureNode.java index 1d2f03544867..8fb20371338a 100644 --- a/slowCheck/src/slowCheck/StructureNode.java +++ b/slowCheck/src/slowCheck/StructureNode.java @@ -97,6 +97,9 @@ class IntData implements StructureElement, Shrink.ElementaryShrink { if (value == 0) return Collections.emptyList(); Set builder = new LinkedHashSet<>(); + if (distribution.isValidValue(0)) { + builder.add(new IntData(0, distribution)); + } if (value < 0 && distribution.isValidValue(-value)) { builder.add(new IntData(-value, distribution)); } diff --git a/slowCheck/test/slowCheck/GeneratorTest.java b/slowCheck/test/slowCheck/GeneratorTest.java index 87cd5d5349fa..931e2fffa18a 100644 --- a/slowCheck/test/slowCheck/GeneratorTest.java +++ b/slowCheck/test/slowCheck/GeneratorTest.java @@ -20,19 +20,19 @@ public class GeneratorTest extends TestCase { public void testMod() { checkFalsified(integers(), i -> i % 12 != 0, - 3); + 1); } public void testListSumMod() { checkFalsified(nonEmptyListOf(integers()), l -> l.stream().mapToInt(Integer::intValue).sum() % 10 != 0, - 118); + 163); } public void testListContainsDivisible() { checkFalsified(nonEmptyListOf(integers()), l -> l.stream().allMatch(i -> i % 10 != 0), - 13); + 11); } public void testStringContains() { @@ -50,7 +50,7 @@ public class GeneratorTest extends TestCase { public void testIsSorted() { checkFalsified(nonEmptyListOf(integers()), l -> l.stream().sorted().collect(Collectors.toList()).equals(l), - 99); + 101); } public void testSuccess() { @@ -61,7 +61,7 @@ public class GeneratorTest extends TestCase { public void testSortedDoublesNonDescending() { checkFalsified(listOf(doubles()), l -> isSorted(l.stream().sorted().collect(Collectors.toList())), - 299); + 113); } private static boolean isSorted(List list) { @@ -76,7 +76,7 @@ public class GeneratorTest extends TestCase { public void testPropertyThrowsException() { checkFalsified(integers(), p -> { throw new AssertionError(p); - }, 32); + }, 1); } public void testSuchThat() { @@ -101,7 +101,7 @@ public class GeneratorTest extends TestCase { public void testLongListsHappen() { checkFalsified(listOf(integers()), l -> l.size() < 200, - 6714); + 781); } public void testNonEmptyList() {