aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author CptAlanSmith <CptAlanSmith@gmail.com>2023-09-26 03:47:24 +0200
committer CptAlanSmith <CptAlanSmith@gmail.com>2023-09-28 21:06:12 +0200
commitbc1a8c3e9a9209d0f2c2b843be4a11f317d0b479 (patch)
treeb9a6aa9a940d16c443d444cd045f3419b7adce93
parent322bc603709d7778b808878c6df63d6cd1f4357b (diff)
Refactoring/tidying
-rw-r--r--src/openvic-simulation/testing/Testing.cpp66
-rw-r--r--src/openvic-simulation/testing/Testing.hpp1
2 files changed, 24 insertions, 43 deletions
diff --git a/src/openvic-simulation/testing/Testing.cpp b/src/openvic-simulation/testing/Testing.cpp
index 4d3d9ea..42df80c 100644
--- a/src/openvic-simulation/testing/Testing.cpp
+++ b/src/openvic-simulation/testing/Testing.cpp
@@ -21,8 +21,8 @@ Testing::Testing(GameManager* game_manager) {
A_006_politics_tests* a_006_politics_tests = new A_006_politics_tests();
test_scripts.push_back(a_006_politics_tests);
- for (int i = 0; i < test_scripts.size(); i++) {
- test_scripts[i]->set_game_manager(game_manager);
+ for (auto test_script : test_scripts) {
+ test_script->set_game_manager(game_manager);
}
}
@@ -33,58 +33,38 @@ Testing::~Testing() {
}
void Testing::execute_all_scripts() {
- for (int i = 0; i < test_scripts.size(); i++) {
- test_scripts[i]->execute_script();
+ for (auto test_script : test_scripts) {
+ test_script->execute_script();
}
}
void Testing::report_results() {
std::ofstream test_results;
- // _mkdir("..\\src\\openvic - simulation\\testing\\test_results"); - replace with compatible version (boost?)
- test_results.open("..\\src\\openvic-simulation\\testing\\test_results\\results.txt");
+ // _mkdir("../src/openvic - simulation/testing/test_results"); - replace with compatible version (boost?)
+ test_results.open("../src/openvic-simulation/testing/test_results/results.txt");
for (auto test_script : test_scripts) {
- std::vector<OpenVic::Requirement*> reqs = test_script->get_requirements();
- std::vector<OpenVic::Requirement*> passed_reqs = test_script->get_passed_requirements();
- std::vector<OpenVic::Requirement*> failed_reqs = test_script->get_failed_requirements();
- std::vector<OpenVic::Requirement*> untested_reqs = test_script->get_untested_requirements();
+ std::vector<Requirement*> reqs = test_script->get_requirements();
+ std::vector<Requirement*> passed_reqs = test_script->get_passed_requirements();
+ std::vector<Requirement*> failed_reqs = test_script->get_failed_requirements();
+ std::vector<Requirement*> untested_reqs = test_script->get_untested_requirements();
test_results << test_script->get_script_name() << ":" << std::endl;
- test_results << "\t" << "Requirements for Test" << std::endl;
- test_results << "\t";
- for (auto req : reqs) {
- test_results << req->get_id() << " ";
- }
- if (reqs.size() < 1) test_results << "None";
- test_results << std::endl << std::endl;
-
- test_results << "\t"<< "Passed Requirements" << std::endl;
- test_results << "\t";
- for (auto req : passed_reqs) {
- test_results << req->get_id() << " ";
- }
- if (passed_reqs.size() < 1) test_results << "None";
- test_results << std::endl << std::endl;
-
- test_results << "\t" << "Failed Requirements" << std::endl;
- test_results << "\t";
- for (auto req : failed_reqs) {
- test_results << req->get_id() << " ";
- }
- if (failed_reqs.size() < 1) test_results << "None";
- test_results << std::endl << std::endl;
-
- test_results << "\t" << "Untested Requirements" << std::endl;
- test_results << "\t";
- for (auto req : untested_reqs) {
- test_results << req->get_id() << " ";
- }
- if (untested_reqs.size() < 1) test_results << "None";
- test_results << std::endl << std::endl;
+ report_result("Requirements for Test", test_results, reqs);
+ report_result("Passed Requirements", test_results, passed_reqs);
+ report_result("Failed Requirements", test_results, failed_reqs);
+ report_result("Untested Requirements", test_results, untested_reqs);
test_results << std::endl<< std::endl;
}
test_results.close();
+}
- // Create Summary File
-
+void Testing::report_result(std::string req_title, std::ofstream& outfile, std::vector<Requirement*> reqs) {
+ outfile << "\t" << req_title << std::endl;
+ outfile << "\t";
+ for (auto req : reqs) {
+ outfile << req->get_id() << " ";
+ }
+ if (reqs.size() < 1) outfile << "None";
+ outfile << std::endl << std::endl;
}
diff --git a/src/openvic-simulation/testing/Testing.hpp b/src/openvic-simulation/testing/Testing.hpp
index 90c32db..670c95a 100644
--- a/src/openvic-simulation/testing/Testing.hpp
+++ b/src/openvic-simulation/testing/Testing.hpp
@@ -24,5 +24,6 @@ namespace OpenVic {
void execute_all_scripts();
void report_results();
+ void report_result(std::string req_title, std::ofstream& outfile, std::vector<Requirement*> reqs);
};
}