From d89a43554567b5ac389f1c9d82d0cedacd538670 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Mon, 17 Feb 2020 16:57:55 +0300 Subject: [PATCH] [generator_integration_tests] Print all changed counters before fail on TEST macros. --- .../features_tests.cpp | 107 +++++++++++++----- 1 file changed, 81 insertions(+), 26 deletions(-) diff --git a/generator/generator_integration_tests/features_tests.cpp b/generator/generator_integration_tests/features_tests.cpp index a0e75eb6a4..80e08a1a51 100644 --- a/generator/generator_integration_tests/features_tests.cpp +++ b/generator/generator_integration_tests/features_tests.cpp @@ -76,8 +76,41 @@ struct CountryFeaturesCounters m_poi == rhs.m_poi && m_cityTownOrVillage == rhs.m_cityTownOrVillage && m_bookingHotels == rhs.m_bookingHotels; } + + bool operator!=(CountryFeaturesCounters const & rhs) const { return !(*this == rhs); } }; +struct CountryFeatureResults +{ + CountryFeatureResults() = default; + CountryFeatureResults(CountryFeaturesCounters actual, CountryFeaturesCounters expected) + : m_actual(actual), m_expected(expected) + { + } + + CountryFeaturesCounters m_actual; + CountryFeaturesCounters m_expected; +}; + +void TestAndLogCountryFeatures(std::map const & results) +{ + for (auto const & result : results) + { + if (result.second.m_actual != result.second.m_expected) + { + LOG(LINFO, ("Unexpectad result for", result.first, "actual:", result.second.m_actual, + "expected:", result.second.m_expected, + "the difference is:", result.second.m_actual - result.second.m_expected)); + } + } + + for (auto const & result : results) + { + TEST_EQUAL(result.second.m_actual, result.second.m_expected, + (result.first, "difference:", result.second.m_actual - result.second.m_expected)); + } +} + std::string DebugPrint(CountryFeaturesCounters const & cnt) { std::ostringstream out; @@ -202,7 +235,8 @@ public: TEST(Platform::IsFileExistsByFullPath(world), ()); - TestCountry(world, kWorldCounters); + auto const actual = GetCountersForCountry(world); + TEST_EQUAL(actual, kWorldCounters, ("kWorldCounters difference:", actual - kWorldCounters)); } void BuildCountries() @@ -224,10 +258,16 @@ public: rawGenerator.GenerateCountries(); TEST(rawGenerator.Execute(), ()); - TestCountry(northAuckland, kNorthAucklandCounters); - TestCountry(northWellington, kNorthWellingtonCounters); - TestCountry(southCanterbury, kSouthCanterburyCounters); - TestCountry(southSouthland, kSouthSouthlandCounters); + std::map results; + results["kNorthAucklandCounters"] = + CountryFeatureResults(GetCountersForCountry(northAuckland), kNorthAucklandCounters); + results["kNorthWellingtonCounters"] = + CountryFeatureResults(GetCountersForCountry(northWellington), kNorthWellingtonCounters); + results["kSouthCanterburyCounters"] = + CountryFeatureResults(GetCountersForCountry(southCanterbury), kSouthCanterburyCounters); + results["kSouthSouthlandCounters"] = + CountryFeatureResults(GetCountersForCountry(southSouthland), kSouthSouthlandCounters); + TestAndLogCountryFeatures(results); } void BuildCountriesWithComplex() @@ -250,10 +290,20 @@ public: rawGenerator.GenerateCountries(); TEST(rawGenerator.Execute(), ()); - TestCountry(northAuckland, kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters); - TestCountry(northWellington, kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters); - TestCountry(southCanterbury, kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters); - TestCountry(southSouthland, kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters); + std::map results; + results["kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters"] = + CountryFeatureResults(GetCountersForCountry(northAuckland), + kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters); + results["kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters"] = + CountryFeatureResults(GetCountersForCountry(northWellington), + kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters); + results["kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters"] = + CountryFeatureResults(GetCountersForCountry(southCanterbury), + kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters); + results["kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters"] = + CountryFeatureResults(GetCountersForCountry(southSouthland), + kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters); + TestAndLogCountryFeatures(results); } void CheckMixedTagsAndNodes() @@ -278,22 +328,28 @@ public: rawGenerator.GenerateWorld(true /* needMixTags */); TEST(rawGenerator.Execute(), ()); - TestCountry(northAuckland, kNorthAucklandCounters); - TestCountry(northWellington, kNorthWellingtonCounters); - TestCountry(southCanterbury, kSouthCanterburyCounters); - size_t partner1CntReal = 0; - TestCountry(southSouthland, kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters, - [&](auto const & fb) { - static auto const partner1 = classif().GetTypeByPath({"sponsored", "partner1"}); - if (fb.HasType(partner1)) - ++partner1CntReal; - }); + std::map results; + results["kNorthAucklandCounters"] = + CountryFeatureResults(GetCountersForCountry(northAuckland), kNorthAucklandCounters); + results["kNorthWellingtonCounters"] = + CountryFeatureResults(GetCountersForCountry(northWellington), kNorthWellingtonCounters); + results["kSouthCanterburyCounters"] = + CountryFeatureResults(GetCountersForCountry(southCanterbury), kSouthCanterburyCounters); + results["kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters"] = CountryFeatureResults( + GetCountersForCountry( + southSouthland, + [&](auto const & fb) { + static auto const partner1 = classif().GetTypeByPath({"sponsored", "partner1"}); + if (fb.HasType(partner1)) + ++partner1CntReal; + }), + kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters); + results["kWorldCounters"] = CountryFeatureResults(GetCountersForCountry(world), kWorldCounters); + TestAndLogCountryFeatures(results); TEST_EQUAL(partner1CntReal, 4, ()); - - TestCountry(world, kWorldCounters); } void CheckGeneratedData() @@ -348,10 +404,9 @@ public: } private: - void TestCountry( - std::string const & path, CountryFeaturesCounters const & expected, - std::function const & fn = - [](feature::FeatureBuilder const &) {}) + CountryFeaturesCounters GetCountersForCountry( + std::string const & path, std::function const & fn = + [](feature::FeatureBuilder const &) {}) { CHECK(Platform::IsFileExistsByFullPath(path), ()); auto const fbs = feature::ReadAllDatRawFormat(path); @@ -381,7 +436,7 @@ private: fn(fb); } - TEST_EQUAL(actual, expected, ("The difference is:", actual - expected)); + return actual; } void TestGeneratedFile(std::string const & path, size_t fileSize)