diff options
Diffstat (limited to 'src/main/java/au/id')
7 files changed, 36 insertions, 13 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/ShrinkResult.java b/src/main/java/au/id/zancanaro/javacheck/ShrinkResult.java index 6bf3882..f135cee 100644 --- a/src/main/java/au/id/zancanaro/javacheck/ShrinkResult.java +++ b/src/main/java/au/id/zancanaro/javacheck/ShrinkResult.java @@ -5,9 +5,13 @@ import java.util.List; public class ShrinkResult { public final List<Object> args; public final Throwable thrown; + public final int depth; + public final int visited; - public ShrinkResult(List<Object> args, Throwable thrown) { + public ShrinkResult(List<Object> args, Throwable thrown, int depth, int visited) { this.args = args; this.thrown = thrown; + this.depth = depth; + this.visited = visited; } } diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java index c428edc..175cd6c 100644 --- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java +++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java @@ -116,26 +116,30 @@ public class Properties extends BlockJUnit4ClassRunner { private ShrinkResult shrink(ShrinkTree<List<Object>> failed, Throwable originalEx) { // this array is a mutable container so the shutdown handler can see the new version ShrinkResult[] smallest = new ShrinkResult[]{ - new ShrinkResult(failed.getValue(), originalEx)}; + new ShrinkResult(failed.getValue(), originalEx, 0, 0)}; Thread shutdownHandler = makeShutdownHandler(smallest, originalEx); Runtime.getRuntime().addShutdownHook(shutdownHandler); + int depth = 0; + int visited = 0; Set<List<Object>> seenArgs = new HashSet<>(); Iterator<ShrinkTree<List<Object>>> trees = failed.getChildren().iterator(); while (trees.hasNext()) { ShrinkTree<List<Object>> tree = trees.next(); List<Object> value = tree.getValue(); - boolean haveSeen = seenArgs.add(Arrays.asList(value)); - if (haveSeen) { + boolean notSeen = seenArgs.add(Arrays.asList(value)); + if (notSeen) { + visited++; try { runTest(value.toArray()); } catch (AssumptionViolatedException ex) { // ignore, because it's not useful } catch (Throwable ex) { - smallest[0] = new ShrinkResult(tree.getValue(), ex); + smallest[0] = new ShrinkResult(tree.getValue(), ex, depth, visited); Iterator<ShrinkTree<List<Object>>> children = tree.getChildren().iterator(); if (children.hasNext()) { + depth++; trees = children; } else { break; diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java b/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java index 5f89ca8..4f02a56 100644 --- a/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java +++ b/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java @@ -9,12 +9,12 @@ import java.util.List; public class PropertyError extends AssertionError { public PropertyError(String methodName, long seed, ShrinkResult shrunk) { super(shrunk.thrown.getMessage() == null ? - String.format("%s(%s)%n\tSeed: %s", + String.format("%s(%s)%n\tSeed: %s%n\tVisited: %s; Depth: %s", methodName, joinArgs(shrunk.args), - seed): - String.format("%s(%s)%n\tSeed: %s%n%s", + seed, shrunk.visited, shrunk.depth): + String.format("%s(%s)%n\tSeed: %s%n\tVisited: %s; Depth: %s%n%s", methodName, joinArgs(shrunk.args), - seed, + seed, shrunk.visited, shrunk.depth, shrunk.thrown.getMessage())); initCause(shrunk.thrown); } diff --git a/src/main/java/au/id/zancanaro/javacheck/state/CommandList.java b/src/main/java/au/id/zancanaro/javacheck/state/CommandList.java index 31fbc12..6dc8976 100644 --- a/src/main/java/au/id/zancanaro/javacheck/state/CommandList.java +++ b/src/main/java/au/id/zancanaro/javacheck/state/CommandList.java @@ -11,6 +11,10 @@ public class CommandList<S> { this.commands = new ArrayList<>(commands); } + public int size() { + return commands.size(); + } + public CommandResult<S> run(S initialState) { Map<Integer, Object> values = new HashMap<>(); CommandResult<S> result = CommandResult.success(initialState); @@ -86,9 +90,9 @@ public class CommandList<S> { while (iterator.hasNext()) { builder.append(iterator.next()); if (iterator.hasNext()) { - builder.append(", "); + builder.append(", \n\t"); } } - return builder.toString(); + return "\n\t" + builder.toString(); } } diff --git a/src/main/java/au/id/zancanaro/javacheck/state/CommandListGenerator.java b/src/main/java/au/id/zancanaro/javacheck/state/CommandListGenerator.java index c5cda59..0eb1793 100644 --- a/src/main/java/au/id/zancanaro/javacheck/state/CommandListGenerator.java +++ b/src/main/java/au/id/zancanaro/javacheck/state/CommandListGenerator.java @@ -3,8 +3,15 @@ package au.id.zancanaro.javacheck.state; import au.id.zancanaro.javacheck.Generator; import au.id.zancanaro.javacheck.ShrinkTree; +import java.util.Arrays; import java.util.Random; +import java.util.Spliterator; +import java.util.Spliterators; import java.util.function.Function; +import java.util.function.IntConsumer; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import static au.id.zancanaro.javacheck.Generator.pure; import static au.id.zancanaro.javacheck.Generators.noShrink; diff --git a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java index d2f3419..de0dfc5 100644 --- a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java +++ b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java @@ -46,7 +46,7 @@ public class CommandValue<T> { @SuppressWarnings("unchecked") public T get() { - if (values.containsKey(id)) { + if (values != null && values.containsKey(id)) { return (T) values.get(id); } else { throw new NoSuchElementException("Concrete values cannot be supplied prior to being calculated"); diff --git a/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java b/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java index 92a90f9..85f6fdd 100644 --- a/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java +++ b/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java @@ -43,6 +43,10 @@ public class GeneratedCommand<S, A, R> { @Override public String toString() { - return "#{" + id + "} = " + command + " <- " + args; + if (args == null) { + return "#{" + id + "} = " + command; + } else { + return "#{" + id + "} = " + command + " <- " + args; + } } } |