Skip to content

Commit

Permalink
refactor: change weather class to namespace (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Jun 24, 2024
1 parent 7124858 commit eab8aa8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
26 changes: 11 additions & 15 deletions include/faker-cxx/Weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

#include <string_view>

namespace faker
namespace faker::weather
{
class Weather
{
public:
/**
* @brief Generated a random weather description
*
* @return String_View A random weather description
*
* @code
* Weather::description(); // "Sunny"
* @endcode
*/
static std::string_view weatherDescription();
};
/**
* @brief Generated a random weather description
*
* @return A random weather description
*
* @code
* weather::weatherDescription(); // "Sunny"
* @endcode
*/
std::string_view weatherDescription();
}
4 changes: 2 additions & 2 deletions src/modules/weather/Weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "faker-cxx/Helper.h"
#include "WeatherData.h"

namespace faker
namespace faker::weather
{
std::string_view Weather::weatherDescription()
std::string_view weatherDescription()
{
return Helper::arrayElement(weatherDescriptions);
}
Expand Down
22 changes: 16 additions & 6 deletions src/modules/weather/WeatherData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
#include <array>
#include <string_view>

namespace faker
namespace faker::weather
{
const auto weatherDescriptions = std::to_array<std::string_view>({
"clear sky", "few clouds", "scattered clouds",
"broken clouds", "shower rain", "rainy",
"thunderstorm", "snowy", "misty",
"smoky", "haze", "sunny",
"cloudy", "windy", "dark",
"clear sky",
"few clouds",
"scattered clouds",
"broken clouds",
"shower rain",
"rainy",
"thunderstorm",
"snowy",
"misty",
"smoky",
"haze",
"sunny",
"cloudy",
"windy",
"dark",
"foggy",
});

Expand Down
4 changes: 2 additions & 2 deletions tests/modules/weather/WeatherTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "weather/WeatherData.h"

using namespace ::testing;
using namespace faker;
using namespace faker::weather;

class WeatherTest : public Test
{
Expand All @@ -17,7 +17,7 @@ class WeatherTest : public Test

TEST_F(WeatherTest, shouldGenerateWeatherDescription)
{
const std::string_view generatedWeatherDescription = Weather::weatherDescription();
const std::string_view generatedWeatherDescription = weatherDescription();

ASSERT_TRUE(std::ranges::any_of(weatherDescriptions,
[generatedWeatherDescription](const std::string_view& weatherDescription)
Expand Down

0 comments on commit eab8aa8

Please sign in to comment.