Skip to content

Commit

Permalink
refactor: videogame module migrate (#688)
Browse files Browse the repository at this point in the history
video module migration from class to functions within videogame namespace

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jun 24, 2024
1 parent 0e4bf07 commit 532b2a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
14 changes: 5 additions & 9 deletions include/faker-cxx/VideoGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

#include <string_view>

namespace faker
namespace faker::videogame
{
class VideoGame
{
public:
/**
* @brief Returns a random video game name.
*
Expand All @@ -16,7 +13,7 @@ class VideoGame
* VideoGame::gameTitle() // "Rayman Arena"
* @endcode
*/
static std::string_view gameTitle();
std::string_view gameTitle();

/**
* @brief Returns a random video game genre.
Expand All @@ -27,7 +24,7 @@ class VideoGame
* VideoGame::genre() // "Platformer"
* @endcode
*/
static std::string_view genre();
std::string_view genre();

/**
* @brief Returns a random video game platform.
Expand All @@ -38,7 +35,7 @@ class VideoGame
* VideoGame::platform() // "Playstation 5"
* @endcode
*/
static std::string_view platform();
std::string_view platform();

/**
* @brief Returns a random video game studio name.
Expand All @@ -49,6 +46,5 @@ class VideoGame
* VideoGame::studioName() // "Activision Blizzard"
* @endcode
*/
static std::string_view studioName();
};
std::string_view studioName();
}
18 changes: 9 additions & 9 deletions src/modules/videoGame/VideoGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
#include "faker-cxx/Helper.h"
#include "VideoGameData.h"

namespace faker
namespace faker::videogame
{
std::string_view VideoGame::gameTitle()
std::string_view gameTitle()
{
return Helper::arrayElement(videoGame::videoGameNames);
return Helper::arrayElement(videoGameNames);
}

std::string_view VideoGame::genre()
std::string_view genre()
{
return Helper::arrayElement(videoGame::videoGameGenres);
return Helper::arrayElement(videoGameGenres);
}

std::string_view VideoGame::platform()
std::string_view platform()
{
return Helper::arrayElement(videoGame::platforms);
return Helper::arrayElement(platforms);
}

std::string_view VideoGame::studioName()
std::string_view studioName()
{
return Helper::arrayElement(videoGame::studioNames);
return Helper::arrayElement(studioNames);
}
}
5 changes: 1 addition & 4 deletions src/modules/videoGame/VideoGameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <array>
#include <string_view>

namespace faker
{
namespace videoGame
namespace faker::videogame
{
const auto videoGameNames = std::to_array<std::string_view>({
"#killallzombies",
Expand Down Expand Up @@ -3594,4 +3592,3 @@ const auto studioNames = std::to_array<std::string_view>({
});

}
}
17 changes: 9 additions & 8 deletions tests/modules/videoGame/VideoGameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace ::testing;
using namespace faker;
using namespace faker::videogame;

class VideoGameTest : public Test
{
Expand All @@ -17,32 +18,32 @@ class VideoGameTest : public Test

TEST_F(VideoGameTest, shouldGenerateGameTitle)
{
const auto generatedGameTitle = VideoGame::gameTitle();
const auto generatedGameTitle = gameTitle();

ASSERT_TRUE(std::ranges::any_of(videoGame::videoGameNames, [generatedGameTitle](const std::string_view& gameTitle)
ASSERT_TRUE(std::ranges::any_of(videoGameNames, [generatedGameTitle](const std::string_view& gameTitle)
{ return generatedGameTitle == gameTitle; }));
}

TEST_F(VideoGameTest, shouldGenerateGenre)
{
const auto generatedGenre = VideoGame::genre();
const auto generatedGenre = genre();

ASSERT_TRUE(std::ranges::any_of(videoGame::videoGameGenres, [generatedGenre](const std::string_view& genre)
ASSERT_TRUE(std::ranges::any_of(videoGameGenres, [generatedGenre](const std::string_view& genre)
{ return generatedGenre == genre; }));
}

TEST_F(VideoGameTest, shouldGeneratePlatform)
{
const auto generatedPlatform = VideoGame::platform();
const auto generatedPlatform = platform();

ASSERT_TRUE(std::ranges::any_of(videoGame::platforms, [generatedPlatform](const std::string_view& platform)
ASSERT_TRUE(std::ranges::any_of(platforms, [generatedPlatform](const std::string_view& platform)
{ return generatedPlatform == platform; }));
}

TEST_F(VideoGameTest, shouldGenerateStudioName)
{
const auto generatedStudioName = VideoGame::studioName();
const auto generatedStudioName = studioName();

ASSERT_TRUE(std::ranges::any_of(videoGame::studioNames, [generatedStudioName](const std::string_view& studioName)
ASSERT_TRUE(std::ranges::any_of(studioNames, [generatedStudioName](const std::string_view& studioName)
{ return generatedStudioName == studioName; }));
}

0 comments on commit 532b2a8

Please sign in to comment.