Skip to content

Commit

Permalink
test: phone module testcase added
Browse files Browse the repository at this point in the history
* test case added to phone module for code coverage

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jul 26, 2024
1 parent b427d69 commit cee43b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions include/faker-cxx/phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ enum class PhoneNumberCountryFormat;
* @returns Random phone number based on country phone number template.
*
* @code
* faker::phone::number() // "234-532-654"
* faker::phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494"
* @endcode
*/
FAKER_CXX_EXPORT std::string phoneNumberByCountry(PhoneNumberCountryFormat format);
FAKER_CXX_EXPORT std::string phoneNumberByCountry(std::optional<PhoneNumberCountryFormat> format = std::nullopt);

/**
* @brief Returns IMEI number.
Expand Down Expand Up @@ -325,6 +326,6 @@ enum class PhoneNumberCountryFormat
WesternSahara,
Yemen,
Zambia,
Zimbabwe
Zimbabwe,
};
}
13 changes: 7 additions & 6 deletions src/modules/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ std::string phoneNumberByFormat(std::optional<std::string> format)
return helper::replaceSymbolWithNumber(selectedFormat);
}

std::string phoneNumberByCountry(PhoneNumberCountryFormat format)
std::string phoneNumberByCountry(std::optional<PhoneNumberCountryFormat> format)
{
std::string countryFormat = phoneNumberFormatMap.at(format);
std::string countryFormat = (format)? phoneNumberFormatMap.at(*format) :
phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);;

if (countryFormat.empty())
{
return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);
}
// if (countryFormat.empty())
// {
// return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);
// }

return helper::replaceSymbolWithNumber(countryFormat);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/phone_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const auto phoneNumbers = std::to_array<std::string_view>({
"+212 (###) ####", // Western Sahara
"+967 (###) ###-####", // Yemen
"+260 (###) ###-####", // Zambia
"+263 (###) ####" // Zimbabwe
"+263 (###) ####", // Zimbabwe
});

}
8 changes: 8 additions & 0 deletions tests/modules/phone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ TEST_F(PhoneTest, NumberWithCountryFormat)
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber));
}

TEST_F(PhoneTest, NumberWithEmptyCountryFormat)
{
const auto generatedPhoneNumber = phoneNumberByCountry();

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

TEST_F(PhoneTest, IMEIGeneration)
{
auto generatedImei = imei();
Expand Down

0 comments on commit cee43b8

Please sign in to comment.