Closed jrife closed 4 years ago
So I think I figured it out. It looks like in my case I wasn't advancing the state in one of the command's NextState
calls so it messed up some of my logic. I fixed that and it's working as expected with commands being generated based on the model's state.
I have a scenario where I'd like to generate commands for a system under test based on the current state of the system. For example, let's say my system under test is an on-disk set of strings and I've modeled it with an in-memory set. It supports two operations: Add and Has:
Add() string
adds a random string to the set and returns this stringHas(s string) bool
returns true if the given string is in the setTo test this system I might have a generator for
Add
andHas
commands and my test would apply the commands to each system and check that the results match. When I generate myHas
commands it would be useful if the current in-memory state could inform my generator so that I ensure that the string I'm passing toHas
actually was added to the set. Would thestate
parameter of theGenCommandFunc
function allow me to do something like this?Here's the general idea I had for how I might structure the generators:
In a scenario like this it's difficult because passing any random string to
Has()
would probably result in it returning false. It's very unlikely that a randomly generated string would match one returned by the system under test. What is the intended use of that parameter in theGenCommandFunc
function? Is there a better way to construct generators for commands where the parameters of one command might rely on the result of another?