From 322bc603709d7778b808878c6df63d6cd1f4357b Mon Sep 17 00:00:00 2001 From: CptAlanSmith Date: Mon, 25 Sep 2023 22:18:19 +0100 Subject: Economy test finish --- src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/openvic-simulation/testing/test_scripts') 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..9f0ddbd 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 @@ -504,7 +504,10 @@ namespace OpenVic { } 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(); + 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(); + std::string base_price = ss.str(); Requirement* req = get_requirement_by_id(req_name); req->set_target_value(value); req->set_actual_value(base_price); -- cgit v1.2.3-56-ga3b1 From dbace1d971b604063455200b277fb2bc21cd5978 Mon Sep 17 00:00:00 2001 From: CptAlanSmith Date: Wed, 27 Sep 2023 00:34:31 +0100 Subject: Abstracted out a general test method to TestScript --- scripts | 2 +- src/openvic-simulation/testing/TestScript.cpp | 9 +++++++++ src/openvic-simulation/testing/TestScript.hpp | 3 +++ .../testing/test_scripts/A_002_economy_tests.cpp | 13 ++++++------- 4 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/openvic-simulation/testing/test_scripts') diff --git a/scripts b/scripts index 3060e56..925a38d 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 3060e56388ac00d90deb6693ec19d47bad52deb2 +Subproject commit 925a38d4d8aef200823f50345dfa2570891454c4 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 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/test_scripts/A_002_economy_tests.cpp b/src/openvic-simulation/testing/test_scripts/A_002_economy_tests.cpp index 9f0ddbd..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,16 +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) { + 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(); + 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(); - 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); + + // Perform req checks + pass_or_fail_req_with_actual_and_target_values(req_name, target_value, base_price); } }; } -- cgit v1.2.3-56-ga3b1