Skip to content

Commit

Permalink
Merge branch 'main' into num_ns_migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
00thirdeye00 authored Jun 25, 2024
2 parents e4d1f35 + 02fa3e7 commit df009bc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 81 deletions.
18 changes: 7 additions & 11 deletions include/faker-cxx/Music.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,38 @@

#include <string_view>

namespace faker
namespace faker::music
{
class Music
{
public:
/**
* @brief Returns a random artist.
*
* @returns Artist.
*
* @code
* Music::artist() // "Nirvana"
* music::artist() // "Nirvana"
* @endcode
*/
static std::string_view artist();
std::string_view artist();

/**
* @brief Returns a random music genre.
*
* @returns Music genre.
*
* @code
* Music::genre() // "Rock"
* music::genre() // "Rock"
* @endcode
*/
static std::string_view genre();
std::string_view genre();

/**
* @brief Returns a random song name.
*
* @returns Song name.
*
* @code
* Music::songName() // "Light My Fire"
* music::songName() // "Light My Fire"
* @endcode
*/
static std::string_view songName();
};
std::string_view songName();
}
43 changes: 18 additions & 25 deletions include/faker-cxx/Phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
#include <string_view>
#include <unordered_map>

namespace faker
namespace faker::phone
{
enum class PhoneNumberCountryFormat;

class Phone
{
public:
/**
* @brief Returns a random phone number.
*
Expand All @@ -20,45 +16,45 @@ class Phone
* @returns Random phone number.
*
* @code
* Phone::number() // "961-770-7727"
* Phone::number("501-###-###") // "501-039-841"
* Phone::number("+48 91 ### ## ##") // "+48 91 463 61 70"
* phone::number() // "961-770-7727"
* phone::number("501-###-###") // "501-039-841"
* phone::number("+48 91 ### ## ##") // "+48 91 463 61 70"
* @endcode
*/
static std::string number(std::optional<std::string> = std::nullopt);
std::string number(std::optional<std::string> = std::nullopt);

/**
* @brief Returns a random phone platform.
*
* @returns Random phone platform.
*
* @code
* Phone::platform() // "iOS"
* phone::platform() // "iOS"
* @endcode
*/
static std::string_view platform();
std::string_view platform();

/**
* @brief Returns a random phone model.
*
* @returns Random phone model.
*
* @code
* Phone::modelName() // "Samsung Galaxy S22"
* phone::modelName() // "Samsung Galaxy S22"
* @endcode
*/
static std::string_view modelName();
std::string_view modelName();

/**
* @brief Returns a random phone manufacturer.
*
* @returns Random phone manufacturer.
*
* @code
* Phone::manufacturer() // "Sony"
* phone::manufacturer() // "Sony"
* @endcode
*/
static std::string_view manufacturer();
std::string_view manufacturer();

/**
* @brief Returns a random phone number based on country phone number template.
Expand All @@ -68,37 +64,34 @@ class Phone
* @returns Random phone number based on country phone number template.
*
* @code
* Phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494"
* phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494"
* @endcode
*/
static std::string number(PhoneNumberCountryFormat format);
std::string number(PhoneNumberCountryFormat format);

/**
* @brief Returns IMEI number.
*
* @returns IMEI number.
*
* @code
* Phone::imei() // "13-850175-913761-7"
* phone::imei() // "13-850175-913761-7"
* @endcode
*/
static std::string imei();
std::string imei();

/**
* @brief returns a random country area code
*
* @returns Random country area code
*
* @code
* Phone::areaCode() // "+1"
* phone::areaCode() // "+1"
* @endcode
*/
static std::string_view areaCode();
std::string_view areaCode();

private:
static std::unordered_map<PhoneNumberCountryFormat, std::string> createPhoneNumberFormatMap();
static std::unordered_map<PhoneNumberCountryFormat, std::string> phoneNumberFormatMap;
};
std::unordered_map<PhoneNumberCountryFormat, std::string> createPhoneNumberFormatMap();

enum class PhoneNumberCountryFormat
{
Expand Down
14 changes: 7 additions & 7 deletions src/modules/music/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
#include "faker-cxx/Helper.h"
#include "MusicData.h"

namespace faker
namespace faker::music
{
std::string_view Music::artist()
std::string_view artist()
{
return Helper::arrayElement(music::artists);
return Helper::arrayElement(artists);
}

std::string_view Music::genre()
std::string_view genre()
{
return Helper::arrayElement(music::musicGenres);
return Helper::arrayElement(musicGenres);
}

std::string_view Music::songName()
std::string_view songName()
{
return Helper::arrayElement(music::songNames);
return Helper::arrayElement(songNames);
}
}
22 changes: 11 additions & 11 deletions src/modules/phone/Phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include "faker-cxx/Helper.h"
#include "PhoneData.h"

namespace faker
namespace faker::phone
{
std::unordered_map<PhoneNumberCountryFormat, std::string> Phone::phoneNumberFormatMap =
Phone::createPhoneNumberFormatMap();
std::unordered_map<PhoneNumberCountryFormat, std::string> phoneNumberFormatMap =
createPhoneNumberFormatMap();

std::string Phone::number(std::optional<std::string> format)
std::string number(std::optional<std::string> format)
{
std::string selectedFormat;

Expand All @@ -29,7 +29,7 @@ std::string Phone::number(std::optional<std::string> format)
return Helper::replaceSymbolWithNumber(selectedFormat);
}

std::string Phone::number(PhoneNumberCountryFormat format)
std::string number(PhoneNumberCountryFormat format)
{
std::string countryFormat = phoneNumberFormatMap.at(format);

Expand All @@ -41,27 +41,27 @@ std::string Phone::number(PhoneNumberCountryFormat format)
return Helper::replaceSymbolWithNumber(countryFormat);
}

std::string Phone::imei()
std::string imei()
{
return Helper::replaceCreditCardSymbols("##-######-######-L", '#');
}

std::string_view Phone::platform()
std::string_view platform()
{
return Helper::arrayElement(phone::PhonePlatforms);
}

std::string_view Phone::modelName()
std::string_view modelName()
{
return Helper::arrayElement(phone::PhoneModelNames);
}

std::string_view Phone::manufacturer()
std::string_view manufacturer()
{
return Helper::arrayElement(phone::PhoneManufacturers);
}

std::unordered_map<PhoneNumberCountryFormat, std::string> Phone::createPhoneNumberFormatMap()
std::unordered_map<PhoneNumberCountryFormat, std::string> createPhoneNumberFormatMap()
{
std::unordered_map<PhoneNumberCountryFormat, std::string> formatMap;

Expand All @@ -77,7 +77,7 @@ std::unordered_map<PhoneNumberCountryFormat, std::string> Phone::createPhoneNumb
return formatMap;
}

std::string_view Phone::areaCode()
std::string_view areaCode()
{
return Helper::arrayElement(phone::areaCodes);
}
Expand Down
13 changes: 7 additions & 6 deletions tests/modules/music/MusicTest.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::music;

class MusicTest : public Test
{
Expand All @@ -17,24 +18,24 @@ class MusicTest : public Test

TEST_F(MusicTest, shouldGenerateArtist)
{
const auto generatedArtist = Music::artist();
const auto generatedArtist = artist();

ASSERT_TRUE(std::ranges::any_of(music::artists, [generatedArtist](const std::string_view& artist)
ASSERT_TRUE(std::ranges::any_of(artists, [generatedArtist](const std::string_view& artist)
{ return generatedArtist == artist; }));
}

TEST_F(MusicTest, shouldGenerateGenre)
{
const auto generatedGenre = Music::genre();
const auto generatedGenre = genre();

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

TEST_F(MusicTest, shouldGenerateSongName)
{
const auto generatedSongName = Music::songName();
const auto generatedSongName = songName();

ASSERT_TRUE(std::ranges::any_of(music::songNames, [generatedSongName](const std::string_view& songName)
ASSERT_TRUE(std::ranges::any_of(songNames, [generatedSongName](const std::string_view& songName)
{ return generatedSongName == songName; }));
}
Loading

0 comments on commit df009bc

Please sign in to comment.