aboutsummaryrefslogtreecommitdiff
path: root/src/headless/main.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-10-19 13:58:20 +0200
committer hop311 <hop3114@gmail.com>2024-10-29 14:53:14 +0100
commitb7b94da345d66f839164ec25450576525474b357 (patch)
treeeba311a156fd5a1626092362840047e0dd0ed79e /src/headless/main.cpp
parent309deb6a5b28c8e2b24e73d06f1418bb992b4cd7 (diff)
Test that modifier calculation methods produce the same resultsresultant-modifier-test
Diffstat (limited to 'src/headless/main.cpp')
-rw-r--r--src/headless/main.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/headless/main.cpp b/src/headless/main.cpp
index 21e9f7c..92d1d08 100644
--- a/src/headless/main.cpp
+++ b/src/headless/main.cpp
@@ -5,6 +5,8 @@
#include <openvic-simulation/testing/Testing.hpp>
#include <openvic-simulation/utility/Logger.hpp>
+#include <openvic-simulation/ModifierCalculationTestToggle.hpp>
+
using namespace OpenVic;
static void print_help(std::ostream& stream, char const* program_name) {
@@ -75,6 +77,90 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
print_ranking_list("Great Powers", country_instance_manager.get_great_powers());
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
print_ranking_list("All countries", country_instance_manager.get_total_ranking());
+
+#if OV_MODIFIER_CALCULATION_TEST
+ Logger::info("Comparing resultant modifier calculation methods...");
+
+ std::vector<ProvinceInstance> const& provinces =
+ game_manager.get_instance_manager()->get_map_instance().get_province_instances();
+ std::vector<ProvinceInstance> const& provinces_no_add =
+ game_manager.get_instance_manager_no_add()->get_map_instance().get_province_instances();
+
+ ModifierManager const& modifier_manager = game_manager.get_definition_manager().get_modifier_manager();
+
+ if (provinces.size() != provinces_no_add.size()) {
+ Logger::error("ProvinceInstance count mismatch between add and no-add instances!");
+ ret = false;
+ } else {
+ for (size_t idx = 0; idx < provinces.size(); ++idx) {
+ ProvinceInstance const& province = provinces[idx];
+ ProvinceInstance const& province_no_add = provinces_no_add[idx];
+ if (province.get_identifier() != province_no_add.get_identifier()) {
+ Logger::error("ProvinceInstance mismatch at index ", idx, " between add and no-add instances!");
+ ret = false;
+ continue;
+ }
+
+ if (province.get_modifier_sum().get_value_sum().empty()) {
+ Logger::error("ProvinceInstance has no modifiers at ID ", province.get_identifier(), "!");
+ ret = false;
+ }
+
+ for (ModifierManager::modifier_effect_registry_t::storage_type const* modifier_effects : {
+ &modifier_manager.get_leader_modifier_effects(),
+ &modifier_manager.get_unit_terrain_modifier_effects(),
+ &modifier_manager.get_shared_tech_country_modifier_effects(),
+ &modifier_manager.get_technology_modifier_effects(),
+ &modifier_manager.get_base_country_modifier_effects(),
+ &modifier_manager.get_base_province_modifier_effects(),
+ &modifier_manager.get_terrain_modifier_effects()
+ }) {
+ for (ModifierEffect const& effect : *modifier_effects) {
+ const fixed_point_t value = province.get_modifier_effect_value(effect);
+ const fixed_point_t value_no_add = province_no_add.get_modifier_effect_value(effect);
+
+ if (value != value_no_add) {
+ Logger::error(
+ "ProvinceInstance modifier effect value mismatch for effect ", effect.get_identifier(),
+ " at ID ", province.get_identifier(), " between add (", value.to_string(), ") and no-add (",
+ value_no_add.to_string(), ") instances!"
+ );
+ ret = false;
+ continue;
+ }
+
+ std::vector<ModifierSum::modifier_entry_t> contributions = province.get_contributing_modifiers(effect);
+ std::vector<ModifierSum::modifier_entry_t> contributions_no_add =
+ province_no_add.get_contributing_modifiers(effect);
+
+ if (contributions.size() != contributions_no_add.size()) {
+ Logger::error(
+ "ProvinceInstance modifier effect contributing modifier count mismatch for effect ",
+ effect.get_identifier(), " at ID ", province.get_identifier(), " between add (",
+ contributions.size(), ") and no-add (", contributions_no_add.size(), ") instances!"
+ );
+ ret = false;
+ continue;
+ }
+ for (size_t cidx = 0; cidx < contributions.size(); ++cidx) {
+ ModifierSum::modifier_entry_t const& contribution = contributions[cidx];
+ ModifierSum::modifier_entry_t const& contribution_no_add = contributions_no_add[cidx];
+
+ if (contribution != contribution_no_add) {
+ Logger::error(
+ "ProvinceInstance modifier effect contributing modifier mismatch for effect ",
+ effect.get_identifier(), " at ID ", province.get_identifier(), " between add (",
+ contribution.to_string(), ") and no-add (", contribution_no_add.to_string(), ") instances!"
+ );
+ ret = false;
+ continue;
+ }
+ }
+ }
+ }
+ }
+ }
+#endif
} else {
Logger::error("Instance manager not available!");
ret = false;