From 05ec409ce96da92d430c4a8e58b08d46f42d667a Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Fri, 5 Jun 2015 17:30:46 +1000 Subject: More work on the stateful checker; still not perfect, but it's getting better --- .../id/zancanaro/javacheck/statem/QueueTest.java | 88 ---------------------- 1 file changed, 88 deletions(-) delete mode 100644 src/test/java/au/id/zancanaro/javacheck/statem/QueueTest.java (limited to 'src/test/java/au/id/zancanaro/javacheck/statem') diff --git a/src/test/java/au/id/zancanaro/javacheck/statem/QueueTest.java b/src/test/java/au/id/zancanaro/javacheck/statem/QueueTest.java deleted file mode 100644 index 4cd6345..0000000 --- a/src/test/java/au/id/zancanaro/javacheck/statem/QueueTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package au.id.zancanaro.javacheck.statem; - -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.*; - -import static au.id.zancanaro.javacheck.Generator.pure; -import static au.id.zancanaro.javacheck.Generators.integer; -import static au.id.zancanaro.javacheck.Generators.oneOf; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -@RunWith(Properties.class) -public class QueueTest { - private static final Queue queue = new LinkedList<>(); - - @DataSource - public static Generator>> commandGenerator = - new CommandListGenerator<>(state -> oneOf( - pure(new QueuePushCommand()), - pure(new QueuePopCommand()) - )); - - @Property - public void test(CommandList> commands) { - queue.clear(); - CommandResult> result = commands.run(null); - assertFalse(result.isFailed()); - } - - private static class QueuePushCommand extends Command, Integer, Void> { - @Override - public Generator argsGenerator(List integers) { - return integer(); - } - - @Override - public Void runCommand(Integer integer) { - queue.offer(integer); - return null; - } - - @Override - public List nextState(List integers, Integer integer, CommandValue result) { - List nextState = new ArrayList<>(integers == null ? new ArrayList<>() : integers); - nextState.add(integer); - return nextState; - } - - @Override - public String toString() { - return "push"; - } - } - - private static class QueuePopCommand extends Command, Void, Integer> { - @Override - public boolean preCondition(List integers, Void aVoid) { - return integers != null && !integers.isEmpty(); - } - - @Override - public Integer runCommand(Void aVoid) { - return queue.poll(); - } - - @Override - public boolean postCondition(List oldState, List newState, Void aVoid, Integer integer) { - return Objects.equals(integer, oldState.get(0)); - } - - @Override - public List nextState(List integers, Void aVoid, CommandValue result) { - List nextState = new ArrayList<>(integers == null ? new ArrayList<>() : integers); - nextState.remove(0); - return nextState; - } - - @Override - public String toString() { - return "pop"; - } - } -} -- cgit v1.2.3