1 #pragma once
2
3 #include <algorithm>
4 #include <cassert>
5
6 #include "rapidcheck/state/gen/Commands.h"
7 #include "rapidcheck/gen/Exec.h"
8
9 namespace rc {
10 namespace state {
11
12 template <typename Model, typename Sut, typename GenFunc>
check(const Model & initialState,Sut & sut,GenFunc && generationFunc)13 void check(const Model &initialState, Sut &sut, GenFunc &&generationFunc) {
14 check(fn::constant(initialState), sut, std::forward<GenFunc>(generationFunc));
15 }
16
17 template <typename MakeInitialState, typename Sut, typename GenFunc, typename>
check(MakeInitialState && makeInitialState,Sut & sut,GenFunc && generationFunc)18 void check(MakeInitialState &&makeInitialState,
19 Sut &sut,
20 GenFunc &&generationFunc) {
21 const auto commands =
22 *gen::commands(makeInitialState, std::forward<GenFunc>(generationFunc));
23 runAll(commands, makeInitialState, sut);
24 }
25
26 template <typename Model, typename Sut>
isValidCommand(const Command<Model,Sut> & command,const Model & s0)27 bool isValidCommand(const Command<Model, Sut> &command, const Model &s0) {
28 try {
29 command.checkPreconditions(s0);
30 } catch (const ::rc::detail::CaseResult &result) {
31 if (result.type == ::rc::detail::CaseResult::Type::Discard) {
32 return false;
33 }
34 throw;
35 }
36
37 return true;
38 }
39
40 } // namespace state
41 } // namespace rc
42