From b2055f2a1dd2117cdd05ab6596c38c82d3d05240 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 11 Jun 2015 00:27:06 +1000 Subject: Report command lists more nicely (line breaks between commands); report number of nodes visited during shrinking; other small fixes --- src/main/java/au/id/zancanaro/javacheck/state/CommandList.java | 8 ++++++-- .../au/id/zancanaro/javacheck/state/CommandListGenerator.java | 7 +++++++ src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java | 2 +- .../java/au/id/zancanaro/javacheck/state/GeneratedCommand.java | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/main/java/au/id/zancanaro/javacheck/state') 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 { this.commands = new ArrayList<>(commands); } + public int size() { + return commands.size(); + } + public CommandResult run(S initialState) { Map values = new HashMap<>(); CommandResult result = CommandResult.success(initialState); @@ -86,9 +90,9 @@ public class CommandList { 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 { @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 { @Override public String toString() { - return "#{" + id + "} = " + command + " <- " + args; + if (args == null) { + return "#{" + id + "} = " + command; + } else { + return "#{" + id + "} = " + command + " <- " + args; + } } } -- cgit v1.2.3