From c853b7557a755fe0e74efe879d39a910c94459be Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 4 Jun 2021 03:09:36 +0200 Subject: [PATCH] Tests: PityTest11 - add test_linear --- test/test_linear.cc | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/test_linear.cc diff --git a/test/test_linear.cc b/test/test_linear.cc new file mode 100644 index 0000000..3a8f880 --- /dev/null +++ b/test/test_linear.cc @@ -0,0 +1,63 @@ +#include "../src/PityUnit.hh" +#include +#include + +using namespace std; +using namespace pEp; +using namespace pEp::PityTest11; + + +class Car { +private: + int gear_nr = 0; + +public: + void setGear(int nr) + { + gear_nr = nr; + } + + void drive() + { + if (gear_nr > 0 && gear_nr <= 6) { + cout << "cruising" << endl; + } else { + throw runtime_error{ "invalid gear" }; + } + } +}; + +class CarTestModel { +public: + CarTestModel(const string& name) : name{ name }, car{} {} + + string name{}; + Car car; +}; + +void test_setGear(const PityUnit& node) +{ + int gear = 1; + node.log("Setting gear to: " + to_string(gear)); + node.getModel()->car.setGear(gear); +} + +void test_drive(const PityUnit& node) +{ + node.getModel()->car.drive(); +} + +int main(int argc, char* argv[]) +{ + // Linear Test + CarTestModel model{ "CarTestModel" }; + PityUnit testnode_car{ nullptr, "test car", nullptr, &model }; + PityUnit testnode_setGear{ &testnode_car, "test car setGear()", test_setGear }; + PityUnit testnode_driv{ &testnode_setGear, "test car drive()", &test_drive }; + + PityUnit testnode_driv_before_gear{ &testnode_car, + "testnode_driv_before_gear", + &test_drive }; + + testnode_car.run(); +} \ No newline at end of file