aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-28 21:22:39 +0200
committer GitHub <noreply@github.com>2023-09-28 21:22:39 +0200
commit5764126f4a3940320990a9bc3007ba22e89a514c (patch)
treef03e84f8499035a03e2329498e239fb43ad4b614
parentae0be2a8d2e1b717f6c4a4617096f17089ce8701 (diff)
parent5c633065db4f2fd1c511543cab997c075cc9c28e (diff)
Merge pull request #34 from OpenVicProject/Testing
Testing
-rw-r--r--src/openvic-simulation/testing/TestScript.cpp9
-rw-r--r--src/openvic-simulation/testing/TestScript.hpp3
-rw-r--r--src/openvic-simulation/testing/Testing.cpp66
-rw-r--r--src/openvic-simulation/testing/Testing.hpp1
-rw-r--r--src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp16
5 files changed, 45 insertions, 50 deletions
diff --git a/src/openvic-simulation/testing/TestScript.cpp b/src/openvic-simulation/testing/TestScript.cpp
index d9affae..0a9ce6f 100644
--- a/src/openvic-simulation/testing/TestScript.cpp
+++ b/src/openvic-simulation/testing/TestScript.cpp
@@ -40,3 +40,12 @@ void TestScript::set_requirements(std::vector<Requirement*> in_requirements) { r
void TestScript::add_requirement(Requirement* req) { requirements.push_back(req); }
void TestScript::set_game_manager(GameManager* in_game_manager) { game_manager = in_game_manager; }
void TestScript::set_script_name(std::string in_script_name) { script_name = in_script_name; }
+
+// Methods
+void TestScript::pass_or_fail_req_with_actual_and_target_values(std::string req_name, std::string target_value, std::string actual_value) {
+ Requirement* req = get_requirement_by_id(req_name);
+ req->set_target_value(target_value);
+ req->set_actual_value(actual_value);
+ if (target_value == actual_value) req->set_pass(true);
+ else req->set_pass(false);
+}
diff --git a/src/openvic-simulation/testing/TestScript.hpp b/src/openvic-simulation/testing/TestScript.hpp
index 874e083..c278323 100644
--- a/src/openvic-simulation/testing/TestScript.hpp
+++ b/src/openvic-simulation/testing/TestScript.hpp
@@ -34,5 +34,8 @@ namespace OpenVic {
void add_requirement(Requirement* req);
void set_game_manager(GameManager* in_game_manager);
void set_script_name(std::string in_script_name);
+
+ // Methods
+ void pass_or_fail_req_with_actual_and_target_values(std::string req_name, std::string target_value, std::string actual_value);
};
}
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);
};
}
diff --git a/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp b/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp
index aa0e59f..c74c5e9 100644
--- a/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp
+++ b/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp
@@ -503,13 +503,15 @@ namespace OpenVic {
check_base_price("wool", "0.7", "ECON_261");
}
- void check_base_price(std::string identifier, std::string value, std::string req_name) {
- std::string base_price = get_game_manager()->get_good_manager().get_good_by_identifier(identifier)->get_base_price().to_string();
- Requirement* req = get_requirement_by_id(req_name);
- req->set_target_value(value);
- req->set_actual_value(base_price);
- if (base_price == value) req->set_pass(true);
- else req->set_pass(false);
+ void check_base_price(std::string identifier, std::string target_value, std::string req_name) {
+ // Get string of base_price from goods manager
+ fixed_point_t base_price_fp = get_game_manager()->get_good_manager().get_good_by_identifier(identifier)->get_base_price();
+ std::stringstream ss;
+ ss << std::fixed << std::setprecision(1) << base_price_fp.to_double(); // Use a single digit floating point of the value
+ std::string base_price = ss.str();
+
+ // Perform req checks
+ pass_or_fail_req_with_actual_and_target_values(req_name, target_value, base_price);
}
};
}