From 36af5120f3b59b63e33d14232500923e7e8b57bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jo=C5=84ski?= Date: Tue, 10 May 2022 10:33:26 +0200 Subject: [PATCH] [BH-1472] Fix minutes form above hundred Fix minutes form above hundred --- .../BellHybrid/apps/common/CMakeLists.txt | 6 +++ .../apps/common/src/LanguageUtils.cpp | 5 +- .../apps/common/tests/CMakeLists.txt | 12 +++++ .../apps/common/tests/test-LanguageUtils.cpp | 54 +++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 products/BellHybrid/apps/common/tests/CMakeLists.txt create mode 100644 products/BellHybrid/apps/common/tests/test-LanguageUtils.cpp diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index 94cbda585bbce65ca35dc6d890da6ecf1ce045e8..975e190e9621a848a52e6ca8525676c42e9e4a69 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -1,3 +1,5 @@ +module_is_test_entity(bell-applications-common) + add_library(application-bell-common STATIC) add_library(bell::app-common ALIAS application-bell-common) @@ -126,3 +128,7 @@ target_link_libraries(application-bell-common module-gui bell::db ) + +if (${ENABLE_TESTS}) + add_subdirectory(tests) +endif() diff --git a/products/BellHybrid/apps/common/src/LanguageUtils.cpp b/products/BellHybrid/apps/common/src/LanguageUtils.cpp index cf197222e80237f7e3c5a0cd2244f507b9009e42..ad8e8301ba4cdc20693279318775bcb6f9289851 100644 --- a/products/BellHybrid/apps/common/src/LanguageUtils.cpp +++ b/products/BellHybrid/apps/common/src/LanguageUtils.cpp @@ -13,9 +13,10 @@ namespace if (val == 1) { return minuteLower; } + auto core = val % 100; if (utils::getDisplayLanguage() == "Polski") { - if (val < 10 || val > 20) { - if ((val % 10) == 2 || (val % 10) == 3 || (val % 10) == 4) { + if (core < 10 || core > 20) { + if ((core % 10) == 2 || (core % 10) == 3 || (core % 10) == 4) { return minutesLower; } } diff --git a/products/BellHybrid/apps/common/tests/CMakeLists.txt b/products/BellHybrid/apps/common/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d11a0b196fcc1374b0fd98756796417e961fdef9 --- /dev/null +++ b/products/BellHybrid/apps/common/tests/CMakeLists.txt @@ -0,0 +1,12 @@ +add_gtest_executable( + NAME + bell-apps-common-tests + SRCS + test-LanguageUtils.cpp + LIBS + bell::app-common + module-sys + INCLUDE + $ + USE_FS +) diff --git a/products/BellHybrid/apps/common/tests/test-LanguageUtils.cpp b/products/BellHybrid/apps/common/tests/test-LanguageUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d7651f7182a2df23b1c4fab8a1a9d74c03a8be84 --- /dev/null +++ b/products/BellHybrid/apps/common/tests/test-LanguageUtils.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include + +#include +#include + +TEST(MinutesGenitive, Polish) +{ + + using namespace utils::language; + + utils::setDisplayLanguage("Polski"); + + EXPECT_EQ(getCorrectMinutesNumeralForm(0), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(1), utils::translate("common_minute_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(2), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(3), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(4), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(5), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(10), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(11), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(15), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(20), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(22), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(84), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(95), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(100), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(101), utils::translate("common_minutes_lower_genitive")); + EXPECT_EQ(getCorrectMinutesNumeralForm(102), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(1003), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(9999), utils::translate("common_minutes_lower_genitive")); +} + +TEST(MinutesGenitive, English) +{ + + using namespace utils::language; + + utils::setDisplayLanguage("English"); + + EXPECT_EQ(getCorrectMinutesNumeralForm(0), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(1), utils::translate("common_minute_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(5), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(10), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(11), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(15), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(20), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(95), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(100), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(101), utils::translate("common_minutes_lower")); + EXPECT_EQ(getCorrectMinutesNumeralForm(9999), utils::translate("common_minutes_lower")); +}