Skip to content

Commit

Permalink
Changed a test style
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Oct 8, 2024
1 parent 3bc2f19 commit d6a1971
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 72 deletions.
8 changes: 4 additions & 4 deletions src/tests/GOTestExe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ int main() {
*/

/* Instantiate all the test classes here */
new GOTestDrawStop;
new GOTestOrganModel;
new GOTestSwitch;
new GOTestWindchest;
GOTestDrawStop::TestFunctions testDrawStopFunctions;
GOTestOrganModel testOrganModel;
GOTestSwitch testSwitch;
GOTestWindchest testWindchest;
/* end of instanciation */
GOTestResultCollection test_result_collection;
test_result_collection = GOTestCollection::Instance()->run();
Expand Down
130 changes: 69 additions & 61 deletions src/tests/testing/model/GOTestDrawStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,77 @@

#include "model/GOSwitch.h"

void GOTestDrawStop::run() {
std::string GOTestDrawStop::CLASS_NAME = "GOTestDrawStop";
std::string GOTestDrawStop::TestFunctions::TEST_NAME
= CLASS_NAME + "::Functions";

void GOTestDrawStop::TestFunctions::run() {
// test grouping functionality
GOSwitch *sw1 = new GOSwitch(*this->controller);
GOSwitch *sw2 = new GOSwitch(*this->controller);
GOSwitch *sw3 = new GOSwitch(*this->controller);
GOSwitch *sw12 = new GOSwitch(*this->controller);
GOSwitch *sw13 = new GOSwitch(*this->controller);
GOSwitch *sw23 = new GOSwitch(*this->controller);

sw12->SetFunctionType(GODrawstop::FUNCTION_AND);
sw13->SetFunctionType(GODrawstop::FUNCTION_OR);
sw23->SetFunctionType(GODrawstop::FUNCTION_XOR);
sw12->AddControllingDrawstop(sw1, 1, "sw1");
sw12->AddControllingDrawstop(sw2, 2, "sw1");
sw13->AddControllingDrawstop(sw1, 1, "sw2");
sw13->AddControllingDrawstop(sw3, 2, "sw2");
sw23->AddControllingDrawstop(sw2, 1, "sw3");
sw23->AddControllingDrawstop(sw3, 2, "sw3");

GOAssert(!sw12->IsActive(), "false AND false");
GOAssert(!sw13->IsActive(), "false OR false");
GOAssert(!sw23->IsActive(), "false XOR false");

sw1->SetButtonState(true);
GOAssert(!sw12->IsActive(), "true AND false");
GOAssert(sw13->IsActive(), "true OR false");
GOAssert(!sw23->IsActive(), "false XOR false");

sw1->SetButtonState(false);
sw2->SetButtonState(true);
GOAssert(!sw12->IsActive(), "false AND true");
GOAssert(!sw13->IsActive(), "false OR false");
GOAssert(sw23->IsActive(), "true XOR false");

sw1->SetButtonState(true);
GOAssert(sw12->IsActive(), "true AND true");
GOAssert(sw13->IsActive(), "true OR false");
GOAssert(sw23->IsActive(), "true XOR false");

sw1->SetButtonState(false);
sw2->SetButtonState(false);
sw3->SetButtonState(true);
GOAssert(!sw12->IsActive(), "false AND false");
GOAssert(sw13->IsActive(), "false OR true");
GOAssert(sw23->IsActive(), "false XOR true");

sw1->SetButtonState(true);
GOAssert(!sw12->IsActive(), "true AND false");
GOAssert(sw13->IsActive(), "true OR true");
GOAssert(sw23->IsActive(), "false XOR true");

sw1->SetButtonState(false);
sw2->SetButtonState(true);
GOAssert(!sw12->IsActive(), "false AND true");
GOAssert(sw13->IsActive(), "false OR true");
GOAssert(!sw23->IsActive(), "true XOR true");

sw1->SetButtonState(true);
GOAssert(sw12->IsActive(), "true AND true");
GOAssert(sw13->IsActive(), "true OR true");
GOAssert(!sw23->IsActive(), "true XOR true");
GOSwitch sw1(*controller);
GOSwitch sw2(*controller);
GOSwitch sw3(*controller);
GOSwitch sw12(*controller);
GOSwitch sw13(*controller);
GOSwitch sw23(*controller);

sw12.SetFunctionType(GODrawstop::FUNCTION_AND);
sw13.SetFunctionType(GODrawstop::FUNCTION_OR);
sw23.SetFunctionType(GODrawstop::FUNCTION_XOR);
sw12.AddControllingDrawstop(&sw1, 1, "sw1");
sw12.AddControllingDrawstop(&sw2, 2, "sw1");
sw13.AddControllingDrawstop(&sw1, 1, "sw2");
sw13.AddControllingDrawstop(&sw3, 2, "sw2");
sw23.AddControllingDrawstop(&sw2, 1, "sw3");
sw23.AddControllingDrawstop(&sw3, 2, "sw3");

GOAssert(!sw12.IsActive(), "false AND false");
GOAssert(!sw13.IsActive(), "false OR false");
GOAssert(!sw23.IsActive(), "false XOR false");

sw1.SetButtonState(true);
GOAssert(!sw12.IsActive(), "true AND false");
GOAssert(sw13.IsActive(), "true OR false");
GOAssert(!sw23.IsActive(), "false XOR false");

sw1.SetButtonState(false);
sw2.SetButtonState(true);
GOAssert(!sw12.IsActive(), "false AND true");
GOAssert(!sw13.IsActive(), "false OR false");
GOAssert(sw23.IsActive(), "true XOR false");

sw1.SetButtonState(true);
GOAssert(sw12.IsActive(), "true AND true");
GOAssert(sw13.IsActive(), "true OR false");
GOAssert(sw23.IsActive(), "true XOR false");

sw1.SetButtonState(false);
sw2.SetButtonState(false);
sw3.SetButtonState(true);
GOAssert(!sw12.IsActive(), "false AND false");
GOAssert(sw13.IsActive(), "false OR true");
GOAssert(sw23.IsActive(), "false XOR true");

sw1.SetButtonState(true);
GOAssert(!sw12.IsActive(), "true AND false");
GOAssert(sw13.IsActive(), "true OR true");
GOAssert(sw23.IsActive(), "false XOR true");

sw1.SetButtonState(false);
sw2.SetButtonState(true);
GOAssert(!sw12.IsActive(), "false AND true");
GOAssert(sw13.IsActive(), "false OR true");
GOAssert(!sw23.IsActive(), "true XOR true");

sw1.SetButtonState(true);
GOAssert(sw12.IsActive(), "true AND true");
GOAssert(sw13.IsActive(), "true OR true");
GOAssert(!sw23.IsActive(), "true XOR true");

/*
std::string message;
// Check global Switch
GOSwitch *go_switch = new GOSwitch(*this->controller);
GOSwitch *go_switch(*this->controller);
message = "The associated manual should be -1 as it is a global switch!";
this->GOAssert(go_switch->GetAssociatedManualN() == -1, message);
Expand All @@ -77,4 +81,8 @@ void GOTestDrawStop::run() {
*/

// Test AND function of switches

sw23.ClearControllingDrawstops();
sw13.ClearControllingDrawstops();
sw12.ClearControllingDrawstops();
}
17 changes: 10 additions & 7 deletions src/tests/testing/model/GOTestDrawStop.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

#include "GOTest.h"

class GOTestDrawStop : public GOCommonControllerTest {

class GOTestDrawStop {
private:
std::string name = "GOTestDrawStop";
static std::string CLASS_NAME;

public:
GOTestDrawStop() {}
virtual ~GOTestDrawStop() {}
virtual void run();
std::string GetName() { return name; }
class TestFunctions : public GOCommonControllerTest {
private:
static std::string TEST_NAME;

public:
virtual void run() override;
std::string GetName() override { return TEST_NAME; }
};
};

#endif /* GOTESTDRAWSTOP_H */

0 comments on commit d6a1971

Please sign in to comment.