diff --git a/CMakeLists.txt b/CMakeLists.txt index 68a59f87..5b4ce67a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(faker-cxx include(cmake/CompilerWarnings.cmake) include(CMakeDependentOption) -option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" ON) +option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" OFF) option(BUILD_EXAMPLES "Build examples" OFF) option(BUILD_TESTING "Build tests" ON) option(CODE_COVERAGE "Build faker-cxx with coverage support" OFF) diff --git a/include/faker-cxx/word.h b/include/faker-cxx/word.h index 3f5a00ca..5590a9e4 100644 --- a/include/faker-cxx/word.h +++ b/include/faker-cxx/word.h @@ -27,7 +27,7 @@ namespace faker::word * faker::word::sample(5) // "spell" * @endcode */ -FAKER_CXX_EXPORT std::string_view sample(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view sample(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** @@ -44,7 +44,7 @@ FAKER_CXX_EXPORT std::string_view sample(std::optional length = std::n * @endcode */ -FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const Locale locale = Locale::en_US); /** * @brief Returns a string containing a number of space separated random words. @@ -59,7 +59,7 @@ FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const faker:: * faker::word::words(5) // "before hourly patiently dribble equal" * @endcode */ -FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const Locale locale = Locale::en_US); /** @@ -75,7 +75,7 @@ FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const faker::Local * faker::word::wordsLocale(5,faker::locale::en_US) // "before hourly patiently dribble equal" * @endcode */ -FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const Locale locale = Locale::en_US); /** * @brief Returns a random adjective. @@ -91,7 +91,7 @@ FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const faker: * faker::word::adjective(3) // "bad" * @endcode */ -FAKER_CXX_EXPORT std::string_view adjective(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view adjective(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** @@ -107,7 +107,7 @@ FAKER_CXX_EXPORT std::string_view adjective(std::optional length = std * faker::word::adjective(3) // "bad" * @endcode */ -FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const Locale locale = Locale::en_US); /** * @brief Returns a random adverb. @@ -123,7 +123,8 @@ FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const fake * faker::word::adverb(5) // "almost" * @endcode */ -FAKER_CXX_EXPORT std::string_view adverb(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view adverb(std::optional length = std::nullopt,const Locale locale = Locale::en_US); + /** @@ -140,7 +141,7 @@ FAKER_CXX_EXPORT std::string_view adverb(std::optional length = std::n * faker::word::adverbLocale(5) // "almost" * @endcode */ -FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const Locale locale = Locale::en_US); /** * @brief Returns a random conjunction. @@ -156,7 +157,7 @@ FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const faker:: * faker::word::conjunction(6) // "indeed" * @endcode */ -FAKER_CXX_EXPORT std::string_view conjunction(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view conjunction(std::optional length = std::nullopt,const Locale locale = Locale::en_US); @@ -174,7 +175,7 @@ FAKER_CXX_EXPORT std::string_view conjunction(std::optional length = s * faker::word::conjunctionLocale(6) // "indeed" * @endcode */ -FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const Locale locale = Locale::en_US); /** @@ -191,7 +192,7 @@ FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const * faker::word::interjection(4) // "yuck" * @endcode */ -FAKER_CXX_EXPORT std::string_view interjection(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view interjection(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** * @brief Returns a random interjection. @@ -207,7 +208,7 @@ FAKER_CXX_EXPORT std::string_view interjection(std::optional length = * faker::word::interjectionLocale(4) // "yuck" * @endcode */ -FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US) ; +FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, const Locale locale = Locale::en_US) ; /** * @brief Returns a random noun. @@ -223,7 +224,7 @@ FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, con * faker::word::noun(8) // "distance" * @endcode */ -FAKER_CXX_EXPORT std::string_view noun(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view noun(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** @@ -240,7 +241,7 @@ FAKER_CXX_EXPORT std::string_view noun(std::optional length = std::nul * faker::word::nounLocale(8) // "distance" * @endcode */ -FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const Locale locale = Locale::en_US); /** * @brief Returns a random preposition. @@ -256,7 +257,7 @@ FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const faker: * faker::word::preposition(4) // "from" * @endcode */ -FAKER_CXX_EXPORT std::string_view preposition(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view preposition(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** * @brief Returns a random preposition. @@ -272,7 +273,7 @@ FAKER_CXX_EXPORT std::string_view preposition(std::optional length = s * faker::word::prepositionLocale(4) // "from" * @endcode */ -FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const Locale locale = Locale::en_US); /** * @brief Returns a random verb. @@ -288,7 +289,7 @@ FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const * faker::word::verb(9) // "stabilise" * @endcode */ -FAKER_CXX_EXPORT std::string_view verb(std::optional length = std::nullopt,const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view verb(std::optional length = std::nullopt,const Locale locale = Locale::en_US); /** @@ -305,7 +306,7 @@ FAKER_CXX_EXPORT std::string_view verb(std::optional length = std::nul * faker::word::verbLocale(9) // "stabilise" * @endcode */ -FAKER_CXX_EXPORT std::string_view verbLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US); +FAKER_CXX_EXPORT std::string_view verbLocale(unsigned int length=0, const Locale locale = Locale::en_US); /** * @brief Returns random element of length diff --git a/src/modules/internet.cpp b/src/modules/internet.cpp index 0b5f2ef0..7a8f4c98 100644 --- a/src/modules/internet.cpp +++ b/src/modules/internet.cpp @@ -341,11 +341,11 @@ std::string anonymousUsername(unsigned maxLength) else if (maxLength > defaultMax) maxLength = defaultMax; - const std::integral auto adjectiveLocaleength = number::integer(3, 1 + maxLength / 2); + const std::integral auto adjectiveLength = number::integer(3, 1 + maxLength / 2); - const auto nounLocaleength = maxLength - adjectiveLocaleength; + const auto nounLength = maxLength - adjectiveLength; - return common::format("{}{}", word::adjective(adjectiveLocaleength), word::noun(nounLocaleength)); + return common::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength)); } } diff --git a/src/modules/word.cpp b/src/modules/word.cpp index ed6243b3..75d59371 100644 --- a/src/modules/word.cpp +++ b/src/modules/word.cpp @@ -11,7 +11,7 @@ namespace faker::word { -std::string_view sample( std::optional length,const faker::Locale locale) +std::string_view sample( std::optional length,const Locale locale) { if(length) return sampleLocale(length.value(),locale); @@ -20,7 +20,7 @@ std::string_view sample( std::optional length,const faker::Locale } -std::string_view sampleLocale(unsigned int length, const faker::Locale locale) +std::string_view sampleLocale(unsigned int length, const Locale locale) { if(length==0){ length=100; @@ -39,7 +39,7 @@ std::string_view sampleLocale(unsigned int length, const faker::Locale locale) } } -std::string words(unsigned numberOfWords,const faker::Locale locale) +std::string words(unsigned numberOfWords,const Locale locale) { if (numberOfWords == 0) { @@ -48,16 +48,16 @@ std::string words(unsigned numberOfWords,const faker::Locale locale) return wordsLocale(numberOfWords,locale); } -std::string wordsLocale(unsigned numberOfWords,faker::Locale locale) +std::string wordsLocale(unsigned numberOfWords, const Locale locale) { auto localeExt = locale; if (numberOfWords == 0) { return ""; - } - if(_allWords_map.find(locale)==_allWords_map.end()) + } + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeExt = faker::Locale::en_US; + localeExt = Locale::en_US; } std::string combined_words; @@ -102,7 +102,7 @@ std::string wordsLocale(unsigned numberOfWords,faker::Locale locale) return combined_words; } -std::string_view adjective(std::optional length,const faker::Locale locale) +std::string_view adjective(std::optional length,const Locale locale) { if(length) return adjectiveLocale(length.value(),locale); @@ -110,7 +110,7 @@ std::string_view adjective(std::optional length,const faker::Local return adjectiveLocale(0,locale); } -std::string_view adjectiveLocale(unsigned int length, const faker::Locale locale) +std::string_view adjectiveLocale(unsigned int length, const Locale locale) { if(length==0) { @@ -118,15 +118,21 @@ std::string_view adjectiveLocale(unsigned int length, const faker::Locale locale } auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; + localeLocal = Locale::en_US; } auto sorted= _adjetives_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } -std::string_view adverb(std::optional length, const faker::Locale locale) + +std::string_view adverb(const Locale locale) +{ + return adverbLocale(0,locale); +} + +std::string_view adverb(std::optional length, const Locale locale) { //return sortedSizeRandomElement(length, _adverbs_sorted); if(length) @@ -135,17 +141,17 @@ std::string_view adverb(std::optional length, const faker::Locale return adverbLocale(0,locale); } -std::string_view adverbLocale(unsigned int length, const faker::Locale locale) +std::string_view adverbLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; - } - auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) - { - localeLocal = faker::Locale::en_US; } + Locale localeLocal = locale; + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) + { + localeLocal = Locale::en_US; + } auto sorted= _adverbs_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } @@ -159,17 +165,18 @@ std::string_view conjunction(std::optional length, const faker::Lo } -std::string_view conjunctionLocale(unsigned int length, const faker::Locale locale) +std::string_view conjunctionLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; } auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; + localeLocal = Locale::en_US; } + auto sorted= _conjunctions_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } @@ -183,22 +190,24 @@ std::string_view interjection(std::optional length, const faker::L } -std::string_view interjectionLocale(unsigned int length, const faker::Locale locale) +std::string_view interjectionLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; } - auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + auto localeLocal = locale; + + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; + localeLocal = Locale::en_US; } + auto sorted= _interjections_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } -std::string_view noun(std::optional length, const faker::Locale locale) +std::string_view noun(std::optional length, const Locale locale) { if(length) @@ -208,22 +217,22 @@ std::string_view noun(std::optional length, const faker::Locale lo } -std::string_view nounLocale(unsigned int length, const faker::Locale locale) +std::string_view nounLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; } auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; - } + localeLocal = Locale::en_US; + } auto sorted= _nouns_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } -std::string_view preposition(std::optional length, const faker::Locale locale) +std::string_view preposition(std::optional length, const Locale locale) { if(length) @@ -233,22 +242,24 @@ std::string_view preposition(std::optional length, const faker::Lo return prepositionLocale(0,locale); } -std::string_view prepositionLocale(unsigned int length, const faker::Locale locale) +std::string_view prepositionLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; } auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; + localeLocal = Locale::en_US; } + auto sorted=_prepositions_sorted_map.at(localeLocal); return sortedSizeRandomElement(length, sorted); } -std::string_view verb(std::optional length, const faker::Locale locale) +std::string_view verb(std::optional length, const Locale locale) { if(length) @@ -257,16 +268,17 @@ std::string_view verb(std::optional length, const faker::Locale lo return verbLocale(0,locale); } -std::string_view verbLocale(unsigned int length, const faker::Locale locale) +std::string_view verbLocale(unsigned int length, const Locale locale) { if(length==0) { length=100; } auto localeLocal = locale; - if(_allWords_map.find(locale)==_allWords_map.end()) + + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) { - localeLocal = faker::Locale::en_US; + localeLocal = Locale::en_US; } auto sorted=(_verbs_sorted_map).at(localeLocal); diff --git a/src/modules/word_data.h b/src/modules/word_data.h index 3d94bd20..7ecd6409 100644 --- a/src/modules/word_data.h +++ b/src/modules/word_data.h @@ -216,7 +216,8 @@ const auto _adjectives_sorted = []() return adjetives_sorted.at(faker::Locale::en_US); }(); -const auto _adjetives_sorted_map = [](){ +const auto _adjetives_sorted_map = []() +{ std::map> adjetives_sorted; for(auto i: idiomsMapSpan) { @@ -249,7 +250,8 @@ const auto _adverbs_sorted = []() } return adverbs_sorted.at(faker::Locale::en_US); }(); -const auto _adverbs_sorted_map = [](){ +const auto _adverbs_sorted_map = []() +{ std::map> adverbs_sorted; for(auto i: idiomsMapSpan) { @@ -282,7 +284,8 @@ const auto _conjunctions_sorted = []() return conjunctions_sorted.at(faker::Locale::en_US); }(); -const auto _conjunctions_sorted_map = [](){ +const auto _conjunctions_sorted_map = []() +{ std::map> conjunctions_sorted; for(auto i: idiomsMapSpan) { @@ -355,7 +358,8 @@ const auto _nouns_sorted = []() }(); -const auto _nouns_sorted_map = [](){ +const auto _nouns_sorted_map = []() +{ std::map> nouns_sorted; for(auto i: idiomsMapSpan) { diff --git a/src/modules/word_store.h b/src/modules/word_store.h index a590e6ec..8a665032 100644 --- a/src/modules/word_store.h +++ b/src/modules/word_store.h @@ -43531,6 +43531,7 @@ const faker::word::Idioms_Map frFRIdioms{{frFRAdjectives}, {frFRAdverbs}, {frFRNouns},{frFRPrepositions}, {frFRVerbs}}; + const std::map idiomsMapSpan({ {faker::Locale::en_US,{enUSIdioms}}, {faker::Locale::es_AR,{esARIdioms}}, diff --git a/tests/modules/string_test.cpp b/tests/modules/string_test.cpp index ada3ef73..89d5dcfd 100644 --- a/tests/modules/string_test.cpp +++ b/tests/modules/string_test.cpp @@ -146,14 +146,14 @@ TEST_F(StringTest, shouldGenerateSampleString) TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee1) { - const auto sampleLocaleength{20}; + const auto sampleLength{20}; const GuaranteeMap guarantee = {{';', {1, 3}}, {',', {3, 4}}, {'a', {2, 10}}}; for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto generatedSample = sample(std::move(copyGuarantee), sampleLocaleength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(generatedSample.size(), sampleLocaleength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); @@ -170,14 +170,14 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee1) TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee2) { - const auto sampleLocaleength{20}; + const auto sampleLength{20}; const GuaranteeMap guarantee = {{'4', {0, 1}}, {'5', {0, 2}}, {'a', {0, 3}}, {'@', {2, 2}}}; for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto generatedSample = sample(std::move(copyGuarantee), sampleLocaleength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(generatedSample.size(), sampleLocaleength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); @@ -196,14 +196,14 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee2) TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee3) { - const auto sampleLocaleength{20}; + const auto sampleLength{20}; const GuaranteeMap guarantee = {{'(', {0, 4}}, {'{', {0, 2}}, {'\\', {0, 1}}, {'/', {0, 5}}}; for (int i = 0; i < runCount; ++i) { auto copyGuarantee = guarantee; - const auto generatedSample = sample(std::move(copyGuarantee), sampleLocaleength); + const auto generatedSample = sample(std::move(copyGuarantee), sampleLength); - ASSERT_EQ(generatedSample.size(), sampleLocaleength); + ASSERT_EQ(generatedSample.size(), sampleLength); ASSERT_TRUE(std::ranges::all_of( generatedSample, [](char sampleCharacter) { return static_cast(sampleCharacter) >= 33 && static_cast(sampleCharacter) <= 125; })); @@ -222,16 +222,16 @@ TEST_F(StringTest, shouldGenerateSampleStringWithGuarantee3) TEST_F(StringTest, invalidGuaranteeForSample1) { - const auto sampleLocaleength{20}; + const auto sampleLength{20}; GuaranteeMap guarantee = {{'3', {5, 6}}, {':', {6}}, {'A', {10}}}; - ASSERT_THROW(sample(std::move(guarantee), sampleLocaleength), std::invalid_argument); + ASSERT_THROW(sample(std::move(guarantee), sampleLength), std::invalid_argument); } TEST_F(StringTest, invalidGuaranteeForSample2) { - const auto sampleLocaleength{20}; + const auto sampleLength{20}; GuaranteeMap guarantee = {{'a', {3}}, {'A', {10}}, {'~', {2, 2}}}; - ASSERT_THROW(sample(std::move(guarantee), sampleLocaleength), std::invalid_argument); + ASSERT_THROW(sample(std::move(guarantee), sampleLength), std::invalid_argument); } TEST_F(StringTest, shouldGenerateDefaultStringFromCharaters) diff --git a/tests/modules/word_test.cpp b/tests/modules/word_test.cpp index 9d99c1a8..bb42537a 100644 --- a/tests/modules/word_test.cpp +++ b/tests/modules/word_test.cpp @@ -13,6 +13,32 @@ using namespace faker::word; using namespace faker; using namespace ::testing; +namespace{ + + const struct Idioms_Map& getIdiomsMap(Locale locale) + { + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) + { + return enUSIdioms; + } + else + { + return idiomsMapSpan.at(locale); + } + } + bool checkLocale(Locale locale) + { + if(idiomsMapSpan.find(locale)==idiomsMapSpan.end()) + { + return false; + } + else + { + return true; + } + } + +} class WordTest : public Test { public: @@ -277,251 +303,298 @@ TEST_F(WordTest, returnsFirstElementWhenNoLengthMatch) ASSERT_TRUE(result == "three"); } + class WordTestLocale : public TestWithParam { public: }; -TEST_F(WordTestLocale, shouldGenerateadjectiveLocaleocale) +TEST_P(WordTestLocale, shouldGenerateadjectiveLocale) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdjective = adjectiveLocale( 7,locale); - ASSERT_TRUE(std::ranges::any_of(_adjetives_sorted_map.at(locale), [generatedAdjective](const std::string_view& word) + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + + const auto generatedAdjective = adjective( 7,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adjetives, [generatedAdjective](const std::string_view& word) { return word == generatedAdjective; })); } -TEST_F(WordTestLocale, shouldGenerateadjectiveLocaleocaleWithNoLocale) +TEST_P(WordTestLocale, shouldGenerateadjectiveLocaleWithNoLocale) { - - const auto generatedAdjective = adjectiveLocale(); - ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string_view& word) + Locale locale = Locale::en_US; + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdjective = adjective(); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adjetives, [generatedAdjective](const std::string_view& word) { return word == generatedAdjective; })); } -TEST_F(WordTestLocale, shouldGenerateAdjectiveWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateAdjectiveWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdjective = adjectiveLocale(5,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdjective = adjective(5,locale); - ASSERT_TRUE(std::ranges::any_of(_adjetives_sorted_map.at(locale), [generatedAdjective](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adjetives, [generatedAdjective](const std::string_view& word) { return word == generatedAdjective; })); } -TEST_F(WordTestLocale, shouldGenerateAdjectiveWithNonExistingLength) +TEST_P(WordTestLocale, shouldGenerateAdjectiveWithNonExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdjective = adjectiveLocale(0,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdjective = adjective(0,locale); - ASSERT_TRUE(std::ranges::any_of(_adjetives_sorted_map.at(locale), [generatedAdjective](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adjetives, [generatedAdjective](const std::string_view& word) { return word == generatedAdjective; })); } -TEST_F(WordTestLocale, shouldGenerateAdvervsLocale) +TEST_P(WordTestLocale, shouldGenerateAdvervsLocale) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdverb = adverbLocale(7,locale); - ASSERT_TRUE(std::ranges::any_of(_adverbs_sorted_map.at(locale), [generatedAdverb](const std::string_view& word) + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdverb = adverb(7,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adverbs, [generatedAdverb](const std::string_view& word) { return word == generatedAdverb; })); } -TEST_F(WordTestLocale, shouldGenerateadverbLocaleocale2) +TEST_P(WordTestLocale, shouldGenerateadverbLocale2) { - const faker::Locale locale = Locale::en_US; - const auto generatedAdverb = adverb(); - - ASSERT_TRUE(std::ranges::any_of(_adverbs_sorted_map.at(locale), [generatedAdverb](const std::string_view& word) + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdverb = adverb(0,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adverbs, [generatedAdverb](const std::string_view& word) { return word == generatedAdverb; })); } -TEST_F(WordTestLocale, shouldGenerateAdverbWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateAdverbWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdverb = adverbLocale(5,locale); + + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdverb = adverb(5,locale); - ASSERT_TRUE(std::ranges::any_of(_adverbs_sorted_map.at(locale), [generatedAdverb](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adverbs, [generatedAdverb](const std::string_view& word) { return word == generatedAdverb; })); } -TEST_F(WordTestLocale, shouldGenerateAdverbWithNonExistingLength) +TEST_P(WordTestLocale, shouldGenerateAdverbWithNonExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedAdverb = adverbLocale(0,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedAdverb = adverb(0,locale); - ASSERT_TRUE(std::ranges::any_of(_adverbs_sorted_map.at(locale), [generatedAdverb](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.adverbs, [generatedAdverb](const std::string_view& word) { return word == generatedAdverb; })); } -TEST_F(WordTestLocale, shouldGenerateConjunction) +TEST_P(WordTestLocale, shouldGenerateConjunction) { - const auto generatedConjunction = conjunction(); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedConjunction = conjunction(7,locale); - ASSERT_TRUE(std::ranges::any_of(_conjunctions_sorted_map.at(faker::Locale::en_US), [generatedConjunction](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.conjunctions, [generatedConjunction](const std::string_view& word) { return word == generatedConjunction; })); } -TEST_F(WordTestLocale, shouldGenerateConjunctionWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateConjunctionWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedConjunction = conjunctionLocale(5,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedConjunction = conjunction(5,locale); - ASSERT_TRUE(std::ranges::any_of(_conjunctions_sorted_map.at(locale),[generatedConjunction](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.conjunctions,[generatedConjunction](const std::string_view& word) { return word == generatedConjunction; })); } -TEST_F(WordTestLocale, shouldGenerateConjunctionWithLength0) +TEST_P(WordTestLocale, shouldGenerateConjunctionWithLength0) { - const faker::Locale locale = Locale::es_AR; - const auto generatedConjunction = conjunctionLocale(0,locale); - ASSERT_TRUE(std::ranges::any_of(_conjunctions_sorted_map.at(locale), [generatedConjunction](const std::string_view& word) + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedConjunction = conjunction(0,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.conjunctions, [generatedConjunction](const std::string_view& word) { return word == generatedConjunction; })); } -TEST_F(WordTestLocale, shouldGenerateInterjection) +TEST_P(WordTestLocale, shouldGenerateInterjection) { - const faker::Locale locale = Locale::es_AR; - const auto generatedInterjection = interjectionLocale(0,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedInterjection = interjection(0,locale); - ASSERT_TRUE(std::ranges::any_of(_interjections_sorted_map.at(locale), [generatedInterjection](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.interjections, [generatedInterjection](const std::string_view& word) { return word == generatedInterjection; })); } -TEST_F(WordTestLocale, shouldGenerateInterjectionWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateInterjectionWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedInterjection = interjectionLocale(5,locale); - ASSERT_TRUE(std::ranges::any_of(_interjections_sorted_map.at(locale), [generatedInterjection](const std::string_view& word) + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedInterjection = interjection(5,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.interjections, [generatedInterjection](const std::string_view& word) { return word == generatedInterjection; })); } -TEST_F(WordTestLocale, shouldGenerateInterjectionWithLength0) +TEST_P(WordTestLocale, shouldGenerateInterjectionWithLength0) { - const faker::Locale locale = Locale::es_AR; - const auto generatedInterjection = interjectionLocale(0,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedInterjection = interjection(0,locale); - ASSERT_TRUE(std::ranges::any_of(_interjections_sorted_map.at(locale), [generatedInterjection](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.interjections, [generatedInterjection](const std::string_view& word) { return word == generatedInterjection; })); } -TEST_F(WordTestLocale, shouldGenerateNoun) +TEST_P(WordTestLocale, shouldGenerateNoun) { - const faker::Locale locale = Locale::en_US; - const auto generatedNoun = nounLocale(); - + + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedNoun = noun(0,locale); ASSERT_TRUE( - std::ranges::any_of(_nouns_sorted_map.at(locale), [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); + std::ranges::any_of(idiomsMapLocal.nouns, [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); } -TEST_F(WordTestLocale, shouldGenerateNounWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateNounWithExistingLength) { - const faker::Locale locale = Locale::en_US; - const auto generatedNoun = nounLocale(5); + + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedNoun = noun(5,locale); ASSERT_TRUE( - std::ranges::any_of(_nouns_sorted_map.at(locale), [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); + std::ranges::any_of(idiomsMapLocal.nouns, [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); } -TEST_F(WordTestLocale, shouldGenerateNOunWithLength0) +TEST_P(WordTestLocale, shouldGenerateNOunWithLength0) { - const faker::Locale locale = Locale::es_AR; + + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); const auto generatedNoun = nounLocale(0,locale); ASSERT_TRUE( - std::ranges::any_of(_nouns_sorted_map.at(locale), [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); + std::ranges::any_of(idiomsMapLocal.nouns, [generatedNoun](const std::string_view& word) { return word == generatedNoun; })); } -TEST_F(WordTestLocale, shouldGeneratePreposition) +TEST_P(WordTestLocale, shouldGeneratePreposition) { - const faker::Locale locale = Locale::en_US; - const auto generatedPreposition = preposition(); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedPreposition = preposition(0,locale); - ASSERT_TRUE(std::ranges::any_of(_prepositions_sorted_map.at(locale), [generatedPreposition](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.prepositions, [generatedPreposition](const std::string_view& word) { return word == generatedPreposition; })); } -TEST_F(WordTestLocale, shouldGeneratePrepositionWithExistingLength) +TEST_P(WordTestLocale, shouldGeneratePrepositionWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedPreposition = prepositionLocale(5,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedPreposition = preposition(5,locale); - ASSERT_TRUE(std::ranges::any_of(_prepositions_sorted_map.at(locale), [generatedPreposition](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.prepositions, [generatedPreposition](const std::string_view& word) { return word == generatedPreposition; })); } -TEST_F(WordTestLocale, shouldGeneratePrepositionWithLength0) +TEST_P(WordTestLocale, shouldGeneratePrepositionWithLength0) { - const faker::Locale locale = Locale::es_AR; - const auto generatedPreposition = prepositionLocale(0,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedPreposition = preposition(0,locale); - ASSERT_TRUE(std::ranges::any_of(_prepositions_sorted_map.at(locale), [generatedPreposition](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.prepositions, [generatedPreposition](const std::string_view& word) { return word == generatedPreposition; })); } -TEST_F(WordTestLocale, shouldGenerateVerb) +TEST_P(WordTestLocale, shouldGenerateVerb) { - const faker::Locale locale = Locale::en_US; - const auto generatedVerb = verb(); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedVerb = verb(0,locale); - ASSERT_TRUE( - std::ranges::any_of(_verbs_sorted_map.at(locale), [generatedVerb](const std::string_view& word) { return word == generatedVerb; })); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.verbs, [generatedVerb](const std::string_view& word) + { return word == generatedVerb; })); } -TEST_F(WordTestLocale, shouldGenerateVerbWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateVerbWithExistingLength) { - const faker::Locale locale = Locale::es_AR; - const auto generatedVerb = verbLocale(5,locale); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedVerb = verb(5,locale); - ASSERT_TRUE( - std::ranges::any_of(_verbs_sorted_map.at(locale), [generatedVerb](const std::string_view& word) { return word == generatedVerb; })); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.verbs, [generatedVerb](const std::string_view& word) + { return word == generatedVerb; })); } -TEST_F(WordTestLocale, shouldGenerateVerbWithExistingLength0) +TEST_P(WordTestLocale, shouldGenerateVerbWithExistingLength0) { - const faker::Locale locale = Locale::es_AR; - const auto generatedVerb = verbLocale(0,locale); - ASSERT_TRUE( - std::ranges::any_of(_verbs_sorted_map.at(locale), [generatedVerb](const std::string_view& word) { return word == generatedVerb; })); + Locale locale = GetParam(); + auto idiomsMapLocal=getIdiomsMap(locale); + const auto generatedVerb = verb(0,locale); + ASSERT_TRUE(std::ranges::any_of(idiomsMapLocal.verbs, [generatedVerb](const std::string_view& word) + { return word == generatedVerb; })); } TEST_F(WordTestLocale, shouldGenerateSample) { + //default sample should be from en_US faker::Locale locale= faker::Locale::en_US; - const auto generatedSample = sampleLocale(0); + + const auto generatedSample = sample(); ASSERT_TRUE(std::ranges::any_of(_allWords_map.at(locale), [generatedSample](const std::string_view& word) { return word == generatedSample; })); } -TEST_F(WordTestLocale, shouldGenerateSampleWithExistingLength) +TEST_P(WordTestLocale, shouldGenerateSampleWithExistingLength) { - faker::Locale locale= faker::Locale::es_AR; - const auto generatedSample = sampleLocale(5,locale); + Locale locale = GetParam(); + Locale extra=locale; + const auto generatedSample = sample(5,locale); + if(!checkLocale(locale)) + { + extra=Locale::en_US; + } + - ASSERT_TRUE(std::ranges::any_of(_allWords_map.at(locale), [generatedSample](const std::string_view& word) + ASSERT_TRUE(std::ranges::any_of(_allWords_map.at(extra), [generatedSample](const std::string_view& word) { return word == generatedSample; })); } -TEST_F(WordTestLocale, shouldGenerateSampleWithNonExistingLength) +TEST_P(WordTestLocale, shouldGenerateSampleWithNonExistingLength) { - faker::Locale locale= faker::Locale::es_AR; - const auto generatedSample = sampleLocale(0,locale); - - ASSERT_TRUE(std::ranges::any_of(_allWords_map.at(locale), [generatedSample](const std::string_view& word) + Locale locale = GetParam(); + Locale extra=locale; + const auto generatedSample = sample(0,locale); + if(!checkLocale(locale)) + { + extra=Locale::en_US; + } + + ASSERT_TRUE(std::ranges::any_of(_allWords_map.at(extra), [generatedSample](const std::string_view& word) { return word == generatedSample; })); } -TEST_F(WordTestLocale, shouldGenerateWords) +TEST_P(WordTestLocale, shouldGenerateWords) { - faker::Locale locale= faker::Locale::en_US; - const auto generatedWords = wordsLocale(5); + Locale locale = GetParam(); + Locale extra=locale; + + if(!checkLocale(locale)) + { + extra=Locale::en_US; + } + const auto generatedWords = words(5,locale); const auto separatedWords = common::split(generatedWords, " "); - ASSERT_TRUE(std::ranges::all_of(separatedWords, [locale](const std::string& separatedWord) - { return std::ranges::find(_allWords_map.at(locale), separatedWord) !=_allWords_map.at(locale).end(); })); + ASSERT_TRUE(std::ranges::all_of(separatedWords, [extra](const std::string& separatedWord) + { return std::ranges::find(_allWords_map.at(extra), separatedWord) !=_allWords_map.at(extra).end(); })); } TEST_F(WordTestLocale, shouldReturnRandomElementWhenExactLengthNotFound) @@ -540,27 +613,40 @@ TEST_F(WordTestLocale, shouldReturnRandomElementWhenExactLengthNotFound) } } - const auto generatedAdjective = adjectiveLocale(existingLength + 1,locale); + const auto generatedAdjective = adjective(existingLength + 1,locale); ASSERT_TRUE(std::ranges::find(sorted, generatedAdjective) != sorted.end()); ASSERT_TRUE(std::ranges::find(matchingAdjectives, generatedAdjective) == matchingAdjectives.end()); } -TEST_F(WordTestLocale, shouldReturnEmptyStringForZeroWords) +TEST_P(WordTestLocale, shouldReturnEmptyStringForZeroWords) { - faker::Locale locale= faker::Locale::es_AR; - const auto result = wordsLocale(0,locale); + Locale locale = GetParam(); + Locale extra=locale; + + if(!checkLocale(locale)) + { + extra=Locale::en_US; + } + const auto result = words(0,extra); ASSERT_TRUE(result.empty()); } -TEST_F(WordTestLocale, shouldGenerateLargeNumberOfWords) +TEST_P(WordTestLocale, shouldGenerateLargeNumberOfWords) { - faker::Locale locale= faker::Locale::es_AR; + + Locale locale = GetParam(); + Locale extra=locale; + + if(!checkLocale(locale)) + { + extra=Locale::en_US; + } const unsigned int largeWordCount = 300; - const auto generatedWords = wordsLocale(largeWordCount,locale); + const auto generatedWords = words(largeWordCount,extra); const auto separatedWords = common::split(generatedWords, " "); - auto dataset=_allWords_map.at(locale); + auto dataset=_allWords_map.at(extra); ASSERT_EQ(separatedWords.size(), largeWordCount); for (const auto& word : separatedWords) { @@ -606,4 +692,18 @@ TEST_F(WordTestLocale, shouldReturnFrenchSampleifAskedforFrenchWord) auto dataset=_allWords_map.at(locale); ASSERT_TRUE(std::ranges::any_of(dataset, [generatedSample](const std::string_view& word) { return word == generatedSample; })); -} \ No newline at end of file +} + + +TEST_F(WordTestLocale, shouldReturnFrenchSampleifAskedforFrenchWordUsingSample) +{ + faker::Locale locale= faker::Locale::fr_FR; + const auto generatedSample = sample(0,locale); + auto dataset=_allWords_map.at(locale); + ASSERT_TRUE(std::ranges::any_of(dataset, [generatedSample](const std::string_view& word) + { return word == generatedSample; })); +} + + +INSTANTIATE_TEST_SUITE_P(testWordByLocale, WordTestLocale, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); });