Skip to content

Commit

Permalink
refactor: function name changed (#824)
Browse files Browse the repository at this point in the history
* refactor: function name changed

* changed function name from `number` (by format) to `phoneNumberByFormat` in phone module
* changed function name from `number` (by country) to `phoneNumberByCountry` in phone module
* modified test case for `phoneNumberByCountry` function

Signed-off-by: Guru Mehar Rachaputi <[email protected]>

* chore: changelog updated

* moved function name change log to be under v3

Signed-off-by: Guru Mehar Rachaputi <[email protected]>

---------

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 authored Jul 20, 2024
1 parent 15a99e6 commit b3c24ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file

* removed `location.county` method
* renamed all include files from `CamelCase` to `snake_case`
* changed function name from `number` (by format) to `phoneNumberByFormat` in phone module
* changed function name from `number` (by country) to `phoneNumberByCountry` in phone module

## v2.0.0 (27.06.2024)

Expand Down
10 changes: 5 additions & 5 deletions include/faker-cxx/phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ enum class PhoneNumberCountryFormat;
* @returns Random phone number.
*
* @code
* faker::phone::number() // "961-770-7727"
* faker::phone::number("501-###-###") // "501-039-841"
* faker::phone::number("+48 91 ### ## ##") // "+48 91 463 61 70"
* faker::phone::phoneNumberByFormat() // "961-770-7727"
* faker::phone::phoneNumberByFormat("501-###-###") // "501-039-841"
* faker::phone::phoneNumberByFormat("+48 91 ### ## ##") // "+48 91 463 61 70"
* @endcode
*/
FAKER_CXX_EXPORT std::string number(std::optional<std::string> = std::nullopt);
FAKER_CXX_EXPORT std::string phoneNumberByFormat(std::optional<std::string> = std::nullopt);

/**
* @brief Returns a random phone platform.
Expand Down Expand Up @@ -68,7 +68,7 @@ enum class PhoneNumberCountryFormat;
* faker::phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494"
* @endcode
*/
FAKER_CXX_EXPORT std::string number(PhoneNumberCountryFormat format);
FAKER_CXX_EXPORT std::string phoneNumberByCountry(PhoneNumberCountryFormat format);

/**
* @brief Returns IMEI number.
Expand Down
4 changes: 2 additions & 2 deletions src/modules/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace faker::phone
{
std::unordered_map<PhoneNumberCountryFormat, std::string> phoneNumberFormatMap = createPhoneNumberFormatMap();

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

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

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

Expand Down
26 changes: 13 additions & 13 deletions tests/modules/phone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,42 @@ class PhoneTest : public Test

TEST_F(PhoneTest, NumberWithNoFormat)
{
const auto phoneNumber = number();
const auto phoneNumber = phoneNumberByFormat();

ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));
}

TEST_F(PhoneTest, NumberWithFormat)
{
auto format = "501-###-###";
auto phoneNumber = number(format);
auto phoneNumber = phoneNumberByFormat(format);
ASSERT_NE(phoneNumber, format);
ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));

format = "+48 91 ### ## ##";
phoneNumber = number(format);
phoneNumber = phoneNumberByFormat(format);
ASSERT_NE(phoneNumber, format);
ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));

format = "+376 (###) ###-####";
phoneNumber = number(format);
phoneNumber = phoneNumberByFormat(format);
ASSERT_NE(phoneNumber, format);
ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));

format = "+376 (!!!) !!!-!!!!";
phoneNumber = number(format);
phoneNumber = phoneNumberByFormat(format);
ASSERT_NE(phoneNumber, format);
ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));
}

TEST_F(PhoneTest, NumberWithCountryFormat)
{
const auto generatedPhoneNumber = phoneNumberByCountry(PhoneNumberCountryFormat::Zimbabwe);

EXPECT_FALSE(generatedPhoneNumber.empty());
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber));
}

TEST_F(PhoneTest, IMEIGeneration)
{
auto generatedImei = imei();
Expand All @@ -63,14 +71,6 @@ TEST_F(PhoneTest, IMEIGeneration)
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedImei));
}

TEST_F(PhoneTest, NumberFormatTest)
{
const auto generatedPhoneNumber = number(PhoneNumberCountryFormat::Zimbabwe);

EXPECT_FALSE(generatedPhoneNumber.empty());
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber));
}

TEST_F(PhoneTest, PlatformGeneration)
{
const auto generatedPlatform = platform();
Expand Down

0 comments on commit b3c24ba

Please sign in to comment.