1 #pragma once 2 3 #include <rapidcheck/state.h> 4 5 namespace rc { 6 namespace test { 7 8 using IntVec = std::vector<int>; 9 using IntVecCmd = state::Command<IntVec, IntVec>; 10 using IntVecCmdSP = std::shared_ptr<const IntVecCmd>; 11 using IntVecCmds = state::Commands<IntVecCmd>; 12 13 struct PushBack : public IntVecCmd { 14 int value; 15 PushBackPushBack16 PushBack() 17 : value(*gen::arbitrary<int>()) {} 18 PushBackPushBack19 PushBack(int v) 20 : value(v) {} 21 applyPushBack22 void apply(IntVec &s0) const override { s0.push_back(value); } 23 runPushBack24 void run(const IntVec &s0, IntVec &sut) const override { 25 sut.push_back(value); 26 } 27 showPushBack28 void show(std::ostream &os) const override { os << value; } 29 }; 30 31 struct PopBack : public IntVecCmd { checkPreconditionsPopBack32 void checkPreconditions(const IntVec &s0) const override { 33 RC_PRE(!s0.empty()); 34 } 35 applyPopBack36 void apply(IntVec &s0) const override { s0.pop_back(); } 37 runPopBack38 void run(const IntVec &s0, IntVec &sut) const override { sut.pop_back(); } 39 }; 40 41 struct AlwaysFail : public IntVecCmd { runAlwaysFail42 void run(const IntVec &s0, IntVec &sut) const override { 43 RC_FAIL("Always fails"); 44 } 45 }; 46 47 struct PreNeverHolds : public IntVecCmd { checkPreconditionsPreNeverHolds48 void checkPreconditions(const IntVec &s0) const override { 49 RC_DISCARD("Preconditions never hold"); 50 } 51 }; 52 53 struct DiscardInConstructor : public IntVecCmd { DiscardInConstructorDiscardInConstructor54 [[noreturn]] DiscardInConstructor(const IntVec &s0) { RC_DISCARD(); } 55 showDiscardInConstructor56 void show(std::ostream &os) const override { os << "DiscardInConstructor"; } 57 }; 58 59 struct SomeCommand : IntVecCmd {}; 60 61 } // namespace test 62 } // namespace rc 63