diff --git a/track_analyzing/CMakeLists.txt b/track_analyzing/CMakeLists.txt index 8985aadb00..937d26741d 100644 --- a/track_analyzing/CMakeLists.txt +++ b/track_analyzing/CMakeLists.txt @@ -16,3 +16,4 @@ set( omim_add_library(${PROJECT_NAME} ${SRC}) add_subdirectory(track_analyzer) +add_subdirectory(track_analyzing_tests) diff --git a/track_analyzing/track_analyzing_tests/CMakeLists.txt b/track_analyzing/track_analyzing_tests/CMakeLists.txt new file mode 100644 index 0000000000..ff4d1d4aba --- /dev/null +++ b/track_analyzing/track_analyzing_tests/CMakeLists.txt @@ -0,0 +1,36 @@ +project(track_analyzing_tests) + +set( + SRC + ../track_analyzer/utils.cpp + ../track_analyzer/utils.hpp + statistics_tests.cpp +) + +omim_add_test(${PROJECT_NAME} ${SRC}) + +omim_link_libraries( + ${PROJECT_NAME} + track_analyzing + generator + routing + traffic + routing_common + storage + indexer + platform + mwm_diff + bsdiff + geometry + coding + base + icu + jansson + oauthcpp + protobuf + stats_client + gflags + ${LIBZ} +) + +link_qt5_core(${PROJECT_NAME}) diff --git a/track_analyzing/track_analyzing_tests/statistics_tests.cpp b/track_analyzing/track_analyzing_tests/statistics_tests.cpp new file mode 100644 index 0000000000..e34b98ebf7 --- /dev/null +++ b/track_analyzing/track_analyzing_tests/statistics_tests.cpp @@ -0,0 +1,74 @@ +#include "testing/testing.hpp" + +#include "track_analyzing/track_analyzer/utils.hpp" + +#include "storage/routing_helpers.hpp" +#include "storage/storage.hpp" + +#include "routing/segment.hpp" + +#include "traffic/speed_groups.hpp" + +#include "platform/country_file.hpp" + +#include "geometry/latlon.hpp" + +#include + +namespace +{ +using namespace platform; +using namespace routing; +using namespace storage; +using namespace track_analyzing; +using namespace traffic; + +UNIT_TEST(StatTest) +{ + Stat mapping1 = { + {{"Belarus_Minsk Region", 1}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */}, + {{"Russian Federation", 10}, {"Poland", 5} /* Country to number */}}; + + Stat const mapping2 = {{{"Belarus_Minsk Region", 2} /* Mwm to number */}, + {{"Russian Federation", 1}, {"Belarus", 8} /* Country to number */}}; + + mapping1.Add(mapping2); + + Stat const expected = { + {{"Belarus_Minsk Region", 3}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */}, + {{"Russian Federation", 11}, {"Poland", 5}, {"Belarus", 8} /* Country to number */}}; + + TEST_EQUAL(mapping1, expected, ()); +} + +UNIT_TEST(AddStatTest) +{ + DataPoint const dp1(1 /* timestamp */, ms::LatLon(), static_cast(SpeedGroup::G5)); + DataPoint const dp2(2 /* timestamp */, ms::LatLon(), static_cast(SpeedGroup::G5)); + DataPoint const dp3(3 /* timestamp */, ms::LatLon(), static_cast(SpeedGroup::G5)); + DataPoint const dp4(4 /* timestamp */, ms::LatLon(), static_cast(SpeedGroup::G5)); + + uint32_t constexpr kDataPointNumber = 4; + + std::string const kMwmName = "Italy_Sardinia"; + + Track const track1 = {dp1, dp2}; + Track const track2 = {dp3}; + Track const track3 = {dp4}; + + UserToTrack const userToTrack = {{"id1", track1}, {"id2", track2}, {"id3", track3}}; + + Storage storage; + auto numMwmIds = CreateNumMwmIds(storage); + MwmToTracks const mwmToTracks = {{numMwmIds->GetId(CountryFile(kMwmName)), userToTrack}}; + + Stat stat; + AddStat(mwmToTracks, *numMwmIds, storage, stat); + + Stat::NameToCountMapping const expectedMwmToTotalDataMapping = {{kMwmName, kDataPointNumber}}; + TEST_EQUAL(stat.m_mwmToTotalDataPoints, expectedMwmToTotalDataMapping, ()); + + Stat::NameToCountMapping expectedCountryToTotalDataMapping = {{"Italy", kDataPointNumber}}; + TEST_EQUAL(stat.m_countryToTotalDataPoints, expectedCountryToTotalDataMapping, ()); +} +} // namespace