diff --git a/include/faker-cxx/weather.h b/include/faker-cxx/weather.h index da2dc1203..e483db86e 100644 --- a/include/faker-cxx/weather.h +++ b/include/faker-cxx/weather.h @@ -3,17 +3,20 @@ #include #include "faker-cxx/export.h" +#include "faker-cxx/types/locale.h" namespace faker::weather { /** * @brief Generated a random weather description + * + * * @param locale The locale. Defaults to `Locale::en_US`. * * @return A random weather description * * @code - * faker::weather::weatherDescription(); // "Sunny" + * faker::weather::weatherDescription(Locale::en_GB); // "Sunny" * @endcode */ -FAKER_CXX_EXPORT std::string_view weatherDescription(); +FAKER_CXX_EXPORT std::string_view weatherDescription(Locale locale = Locale::en_US); } diff --git a/src/modules/weather.cpp b/src/modules/weather.cpp index 9cb360f51..49ecd921f 100644 --- a/src/modules/weather.cpp +++ b/src/modules/weather.cpp @@ -4,11 +4,27 @@ #include "faker-cxx/helper.h" #include "weather_data.h" +#include namespace faker::weather { -std::string_view weatherDescription() +namespace { - return helper::randomElement(weatherDescriptions); +const std::span getWeatherDefinition(Locale locale) +{ + switch (locale) + { + case Locale::sv_SE: + return svSEWeatherDescriptions; + default: + return enUSWeatherDescriptions; + } +} +} +std::string_view weatherDescription(Locale locale) +{ + const auto& weatherDefinition = getWeatherDefinition(locale); + + return helper::randomElement(weatherDefinition); } } diff --git a/src/modules/weather_data.h b/src/modules/weather_data.h index eff48e7ef..d036c52af 100644 --- a/src/modules/weather_data.h +++ b/src/modules/weather_data.h @@ -5,7 +5,7 @@ namespace faker::weather { -const auto weatherDescriptions = std::to_array({ +const auto enUSWeatherDescriptions = std::to_array({ "broken clouds", "clear sky", "cloudy", @@ -24,4 +24,22 @@ const auto weatherDescriptions = std::to_array({ "windy", }); +const auto svSEWeatherDescriptions = std::to_array({ + "dimma", // fog + "regn", // rain + "snö", // snow + "sol", // sun + "vind", // wind + "is", // ice + "storm", // storm + "vinter", // winter + "kallt", // cold + "snöflinga", // snow flake + "snöstorm", // blizzard + "sommar", // summer + "vår", // spring + "skurar", // showers + "höst", // fall/autumn +}); + } diff --git a/tests/modules/weather_test.cpp b/tests/modules/weather_test.cpp index 6b0dcb37d..071be51d5 100644 --- a/tests/modules/weather_test.cpp +++ b/tests/modules/weather_test.cpp @@ -3,22 +3,47 @@ #include "gtest/gtest.h" +#include "faker-cxx/types/locale.h" #include "faker-cxx/weather.h" #include "weather_data.h" +#include using namespace ::testing; +using namespace faker; using namespace faker::weather; -class WeatherTest : public Test +namespace +{ +const std::span getWeatherDefinition(Locale locale) +{ + switch (locale) + { + case Locale::sv_SE: + return svSEWeatherDescriptions; + default: + return enUSWeatherDescriptions; + } +} +} + +class WeatherTest : public TestWithParam { public: }; -TEST_F(WeatherTest, shouldGenerateWeatherDescription) +TEST_P(WeatherTest, shouldGenerateWeatherDescription) { - const std::string_view generatedWeatherDescription = weatherDescription(); - ASSERT_TRUE(std::ranges::any_of(weatherDescriptions, + const auto locale = GetParam(); + + const auto& weatherDefinition = getWeatherDefinition(locale); + + const std::string_view generatedWeatherDescription = weatherDescription(locale); + + ASSERT_TRUE(std::ranges::any_of(weatherDefinition, [generatedWeatherDescription](const std::string_view& weatherDescription) { return weatherDescription == generatedWeatherDescription; })); } + +INSTANTIATE_TEST_SUITE_P(TestWeatherByLocale, WeatherTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); });