checkCommands<S, M, C> function
void
checkCommands<S, M, C>({
- required FutureOr<
S> setup(- Simulation sim
- required M model(),
- required C generate(
- Random random,
- M model
- required FutureOr<
M> apply(- Simulation sim,
- S subject,
- M model,
- C command,
- int seeds = 100,
- int commands = 30,
- int firstSeed = 0,
- FaultPolicy? faults,
- int maxSteps = 100000,
A property test over sequences of commands.
For each seed, setup creates the thing under test in a fresh simulated
system and model creates a plain-Dart description of how it should
behave. Then, commands times, generate draws a command (it may look
at the model to pick a sensible one) and apply runs it against both,
checks that they agree, and returns the model's next value.
A failure is rethrown as a SimulationFailure with the seed and the commands that led to it. Sequences are not shrunk.
Implementation
void checkCommands<S, M, C>({
required FutureOr<S> Function(Simulation sim) setup,
required M Function() model,
required C Function(Random random, M model) generate,
required FutureOr<M> Function(Simulation sim, S subject, M model, C command)
apply,
int seeds = 100,
int commands = 30,
int firstSeed = 0,
FaultPolicy? faults,
int maxSteps = 100000,
}) {
for (var seed = firstSeed; seed < firstSeed + seeds; seed++) {
final sim = Simulation._(seed, faults, maxSteps, const Duration(hours: 1));
final history = <Object?>[];
try {
sim._run((sim) async {
final subject = await setup(sim);
var current = model();
for (var i = 0; i < commands; i++) {
final command = generate(sim.random, current);
history.add(command);
current = await apply(sim, subject, current, command);
}
}, null);
} catch (e, s) {
throw SimulationFailure(seed, e, s, sim._trace, commands: history);
}
}
}