Skip to content

Commit

Permalink
241 (#327)
Browse files Browse the repository at this point in the history
* 241

* test cases

* Add Codecov configuration

* Dividing it into 2 PRs

* added data file in cpp and test

* using the test data
  • Loading branch information
SidMalladi authored Nov 26, 2023
1 parent 8c140be commit 2fb1853
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
comment: no # do not comment PR with the result

coverage:
range: 50..90 # coverage lower than 50 is red, higher than 90 green, between color code

status:
project: # settings affecting project coverage
default:
target: auto # auto % coverage target
threshold: 5% # allow for 5% reduction of coverage without failing

# do not run coverage on patch nor changes
patch: false
3 changes: 3 additions & 0 deletions include/faker-cxx/Phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Phone
* @endcode
*/
static std::string number(std::optional<std::string> = std::nullopt);
static std::string platform();
static std::string modelName();
static std::string manufacturer();

/**
* @brief Returns a random phone number based on country phone number template.
Expand Down
14 changes: 13 additions & 1 deletion src/modules/phone/Phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "data/PhoneNumbers.h"
#include "faker-cxx/Helper.h"

#include "data/PhoneData.h"
namespace faker
{
std::map<PhoneNumberCountryFormat, std::string> Phone::phoneNumberFormatMap = Phone::createPhoneNumberFormatMap();
Expand Down Expand Up @@ -42,6 +42,18 @@ std::string Phone::imei()
return Helper::replaceCreditCardSymbols("##-######-######-L", '#');
}

std::string Phone::platform() {
return Helper::arrayElement(faker::data::PhonePlatforms);
}

std::string Phone::modelName() {
return Helper::arrayElement(faker::data::PhoneModelNames);
}

std::string Phone::manufacturer() {
return Helper::arrayElement(faker::data::PhoneManufacturers);
}

std::map<PhoneNumberCountryFormat, std::string> Phone::createPhoneNumberFormatMap()
{
std::map<PhoneNumberCountryFormat, std::string> formatMap;
Expand Down
28 changes: 27 additions & 1 deletion src/modules/phone/PhoneTest.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "faker-cxx/Phone.h"

#include <algorithm>
#include <string>
#include <vector>

#include "gtest/gtest.h"

#include "data/PhoneData.h"
#include "data/PhoneNumbers.h"

using namespace ::testing;
using namespace faker;

Expand Down Expand Up @@ -66,3 +68,27 @@ TEST_F(PhoneTest, NumberFormatTest)
EXPECT_FALSE(phoneNumber.empty());
ASSERT_TRUE(isStringNumericWithSpecialChars(phoneNumber));
}

TEST_F(PhoneTest, PlatformGeneration) {
std::string generatedPlatform = Phone::platform();
ASSERT_TRUE(std::ranges::any_of(
faker::data::PhonePlatforms.begin(), faker::data::PhonePlatforms.end(),
[generatedPlatform](const std::string& platform) { return platform == generatedPlatform; }
));
}

TEST_F(PhoneTest, ModelNameGeneration) {
std::string generatedModelName = Phone::modelName();
ASSERT_TRUE(std::ranges::any_of(
faker::data::PhoneModelNames.begin(), faker::data::PhoneModelNames.end(),
[generatedModelName](const std::string& modelName) { return modelName == generatedModelName; }
));
}

TEST_F(PhoneTest, ManufacturerGeneration) {
std::string generatedManufacturer = Phone::manufacturer();
ASSERT_TRUE(std::ranges::any_of(
faker::data::PhoneManufacturers.begin(), faker::data::PhoneManufacturers.end(),
[generatedManufacturer](const std::string& manufacturer) { return manufacturer == generatedManufacturer; }
));
}
19 changes: 19 additions & 0 deletions src/modules/phone/data/PhoneData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <string>
#include <vector>

namespace faker
{
namespace data
{
const std::vector<std::string> PhonePlatforms = {
"Android OS", "iOS", "Windows Phone", "Symbian", "Palm OS", "Tizen",
};
const std::vector<std::string> PhoneModelNames = {
"Samsung Galaxy S9", "iPhone X", "Google Pixel 4", "Samsung Galaxy S22", "iPhone 13",
"iPhone 13", "iPhone 14", "iPhone 15", "Google Pixel 6", "OnePlus 9",
"Xiaomi Mi 11", "Huawei P50", "Oppo Find X3", "Sony Xperia 1 III", "Motorola Edge 20"};
const std::vector<std::string> PhoneManufacturers = {"Samsung", "Apple", "Google", "OnePlus", "Xiaomi",
"Huawei", "Oppo", "Sony", "Motorola"};
}
}

0 comments on commit 2fb1853

Please sign in to comment.