diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a70f2556..d58064760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ set(FAKER_SOURCES src/modules/videoGame/VideoGame.cpp src/modules/videoGame/VideoGameData.cpp src/modules/weather/Weather.cpp + src/modules/weather/WeatherData.cpp src/modules/word/Word.cpp src/common/FormatHelper.cpp src/common/LuhnCheck.cpp diff --git a/include/faker-cxx/Weather.h b/include/faker-cxx/Weather.h index f5a21b2a5..d2ad5efc0 100644 --- a/include/faker-cxx/Weather.h +++ b/include/faker-cxx/Weather.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace faker { @@ -99,13 +99,13 @@ class Weather /** * @brief Generated a random weather description * - * @return String A random weather description + * @return String_View A random weather description * * @code * Weather::description(); // "Sunny" * @endcode */ - static std::string weatherDescription(); + static std::string_view weatherDescription(); /** * @brief Generated a random cloud cover percentage diff --git a/src/modules/weather/Weather.cpp b/src/modules/weather/Weather.cpp index 2002bdf5e..40628ec77 100644 --- a/src/modules/weather/Weather.cpp +++ b/src/modules/weather/Weather.cpp @@ -1,10 +1,10 @@ #include "faker-cxx/Weather.h" -#include +#include -#include "data/WeatherDescription.h" #include "faker-cxx/Helper.h" #include "faker-cxx/Number.h" +#include "WeatherData.h" namespace faker { @@ -51,9 +51,9 @@ int Weather::humidity() return Number::integer(0, 100); } -std::string Weather::weatherDescription() +std::string_view Weather::weatherDescription() { - return Helper::arrayElement(weatherDescriptions); + return Helper::arrayElement(weatherDescriptions); } int Weather::cloudCover() diff --git a/src/modules/weather/data/WeatherDescription.h b/src/modules/weather/WeatherData.cpp similarity index 72% rename from src/modules/weather/data/WeatherDescription.h rename to src/modules/weather/WeatherData.cpp index 0d65c1c42..485275c89 100644 --- a/src/modules/weather/data/WeatherDescription.h +++ b/src/modules/weather/WeatherData.cpp @@ -1,11 +1,9 @@ -#pragma once - -#include -#include +#include "WeatherData.h" namespace faker { -const std::vector weatherDescriptions = { + +const std::array weatherDescriptions = { "clear sky", "few clouds", "scattered clouds", "broken clouds", "shower rain", "rainy", "thunderstorm", "snowy", "misty", @@ -13,4 +11,5 @@ const std::vector weatherDescriptions = { "cloudy", "windy", "dark", "foggy", }; + } diff --git a/src/modules/weather/WeatherData.h b/src/modules/weather/WeatherData.h new file mode 100644 index 000000000..2853e2eac --- /dev/null +++ b/src/modules/weather/WeatherData.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace faker +{ +extern const std::array weatherDescriptions; + +} + diff --git a/tests/modules/weather/WeatherTest.cpp b/tests/modules/weather/WeatherTest.cpp index 82d0c150e..ecf7de6ec 100644 --- a/tests/modules/weather/WeatherTest.cpp +++ b/tests/modules/weather/WeatherTest.cpp @@ -1,11 +1,11 @@ #include "faker-cxx/Weather.h" #include -#include +#include #include "gtest/gtest.h" -#include "weather/data/WeatherDescription.h" +#include "weather/WeatherData.h" using namespace ::testing; using namespace faker; @@ -63,10 +63,10 @@ TEST_F(WeatherTest, shouldGenerateHumidity) TEST_F(WeatherTest, shouldGenerateWeatherDescription) { - std::string generatedWeatherDescription = Weather::weatherDescription(); + const std::string_view generatedWeatherDescription = Weather::weatherDescription(); ASSERT_TRUE(std::ranges::any_of(weatherDescriptions, - [generatedWeatherDescription](const std::string& weatherDescription) + [generatedWeatherDescription](const std::string_view& weatherDescription) { return weatherDescription == generatedWeatherDescription; })); }