diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-07-30 13:51:24 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:58:49 +0300 |
commit | c9ea450ec5fd459b4062dcb15a603f64f7ead06b (patch) | |
tree | 6a1df5edfbd90351785554e942c8847a20f38814 /routing/routing_tests/turns_tts_text_tests.cpp | |
parent | 4d1f0e8ef4cb0a2f2cfb4ee289938b28ee0745e4 (diff) |
Correction after colleagues comments. Adding unit tests. Some other changes.
Diffstat (limited to 'routing/routing_tests/turns_tts_text_tests.cpp')
-rw-r--r-- | routing/routing_tests/turns_tts_text_tests.cpp | 111 |
1 files changed, 107 insertions, 4 deletions
diff --git a/routing/routing_tests/turns_tts_text_tests.cpp b/routing/routing_tests/turns_tts_text_tests.cpp index 019f623afe..054e41693f 100644 --- a/routing/routing_tests/turns_tts_text_tests.cpp +++ b/routing/routing_tests/turns_tts_text_tests.cpp @@ -3,6 +3,9 @@ #include "routing/turns_sound_settings.hpp" #include "routing/turns_tts_text.hpp" +#include "std/string.hpp" + + namespace { using namespace routing::turns; @@ -46,23 +49,123 @@ UNIT_TEST(GetDirectionTextIdTest) UNIT_TEST(GetTtsTextTest) { + string const engShortJson = "\ + {\ + \"in_300_meters\":\"In 300 meters.\",\ + \"in_500_meters\":\"In 500 meters.\",\ + \"then\":\"Then.\",\ + \"make_a_right_turn\":\"Make a right turn.\",\ + \"make_a_left_turn\":\"Make a left turn.\",\ + \"you_have_reached_the_destination\":\"You have reached the destination.\"\ + }"; + + string const rusShortJson = "\ + {\ + \"in_300_meters\":\"Через 300 метров.\",\ + \"in_500_meters\":\"Через 500 метров.\",\ + \"then\":\"Затем.\",\ + \"make_a_right_turn\":\"Поворот направо.\",\ + \"make_a_left_turn\":\"Поворот налево.\",\ + \"you_have_reached_the_destination\":\"Вы достигли конца маршрута.\"\ + }"; + + GetTtsText getTtsText; //Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance, // TurnDirection turnDir, LengthUnits lengthUnits) - GetTtsText getTtsText; - Notification const notifiation1(500, 0, false, TurnDirection::TurnRight, LengthUnits::Meters); Notification const notifiation2(300, 0, false, TurnDirection::TurnLeft, LengthUnits::Meters); Notification const notifiation3(0, 0, false, TurnDirection::ReachedYourDestination, LengthUnits::Meters); + Notification const notifiation4(0, 0, true, TurnDirection::TurnLeft, LengthUnits::Meters); - getTtsText.SetLocale("en"); + getTtsText.SetLocaleWithJson(engShortJson); TEST_EQUAL(getTtsText(notifiation1), "In 500 meters. Make a right turn.", ()); TEST_EQUAL(getTtsText(notifiation2), "In 300 meters. Make a left turn.", ()); TEST_EQUAL(getTtsText(notifiation3), "You have reached the destination.", ()); + TEST_EQUAL(getTtsText(notifiation4), "Then. Make a left turn.", ()); - getTtsText.SetLocale("ru"); + getTtsText.SetLocaleWithJson(rusShortJson); TEST_EQUAL(getTtsText(notifiation1), "Через 500 метров. Поворот направо.", ()); TEST_EQUAL(getTtsText(notifiation2), "Через 300 метров. Поворот налево.", ()); TEST_EQUAL(getTtsText(notifiation3), "Вы достигли конца маршрута.", ()); + TEST_EQUAL(getTtsText(notifiation4), "Затем. Поворот налево.", ()); +} + +UNIT_TEST(GetAllSoundedDistMetersTest) +{ + VecPairDist const allSoundedDistMeters = GetAllSoundedDistMeters(); + + TEST(is_sorted(allSoundedDistMeters.cbegin(), allSoundedDistMeters.cend(), + [](PairDist const & p1, PairDist const & p2) + { + return p1.first < p2.first; + }), ()); + + TEST_EQUAL(allSoundedDistMeters.size(), 17, ()); + PairDist const expected1 = { 50, "in_50_meters" }; + TEST_EQUAL(allSoundedDistMeters[0], expected1, ()); + PairDist const expected2 = { 700, "in_700_meters" }; + TEST_EQUAL(allSoundedDistMeters[8], expected2, ()); + PairDist const expected3 = { 3000, "in_3_kilometers" }; + TEST_EQUAL(allSoundedDistMeters[16], expected3, ()); +} + +UNIT_TEST(GetAllSoundedDistFeet) +{ + VecPairDist const allSoundedDistFeet = GetAllSoundedDistFeet(); + + TEST(is_sorted(allSoundedDistFeet.cbegin(), allSoundedDistFeet.cend(), + [](PairDist const & p1, PairDist const & p2) + { + return p1.first < p2.first; + }), ()); + + TEST_EQUAL(allSoundedDistFeet.size(), 22, ()); + PairDist const expected1 = { 50, "in_50_feet" }; + TEST_EQUAL(allSoundedDistFeet[0], expected1, ()); + PairDist const expected2 = { 700, "in_700_feet" }; + TEST_EQUAL(allSoundedDistFeet[7], expected2, ()); + PairDist const expected3 = { 10560, "in_2_miles" }; + TEST_EQUAL(allSoundedDistFeet[21], expected3, ()); +} + +UNIT_TEST(GetSoundedDistMeters) +{ + vector<uint32_t> const soundedDistMeters = GetSoundedDistMeters(); + VecPairDist const allSoundedDistMeters = GetAllSoundedDistMeters(); + + TEST(is_sorted(soundedDistMeters.cbegin(), soundedDistMeters.cend()), ()); + // Checking that allSounded contains any element of inst. + TEST(find_first_of(soundedDistMeters.cbegin(), soundedDistMeters.cend(), + allSoundedDistMeters.cbegin(), allSoundedDistMeters.cend(), + [](uint32_t p1, PairDist const & p2) + { + return p1 == p2.first; + }) != soundedDistMeters.cend(), ()); + + TEST_EQUAL(soundedDistMeters.size(), 11, ()); + TEST_EQUAL(soundedDistMeters[0], 200, ()); + TEST_EQUAL(soundedDistMeters[7], 900, ()); + TEST_EQUAL(soundedDistMeters[10], 2000, ()); +} + +UNIT_TEST(GetSoundedDistFeet) +{ + vector<uint32_t> soundedDistFeet = GetSoundedDistFeet(); + VecPairDist const allSoundedDistFeet = GetAllSoundedDistFeet(); + + TEST(is_sorted(soundedDistFeet.cbegin(), soundedDistFeet.cend()), ()); + // Checking that allSounded contains any element of inst. + TEST(find_first_of(soundedDistFeet.cbegin(), soundedDistFeet.cend(), + allSoundedDistFeet.cbegin(), allSoundedDistFeet.cend(), + [](uint32_t p1, PairDist const & p2) + { + return p1 == p2.first; + }) != soundedDistFeet.cend(), ()); + + TEST_EQUAL(soundedDistFeet.size(), 11, ()); + TEST_EQUAL(soundedDistFeet[0], 500, ()); + TEST_EQUAL(soundedDistFeet[7], 2000, ()); + TEST_EQUAL(soundedDistFeet[10], 5000, ()); } } // namespace |