Skip to content

Commit

Permalink
chore: remove duplicate api functions (#656)
Browse files Browse the repository at this point in the history
* improve quality of book module

* chore: remove duplicate api functions
  • Loading branch information
cieslarmichal authored Jun 16, 2024
1 parent 3dd30fb commit c12f945
Show file tree
Hide file tree
Showing 19 changed files with 567 additions and 1,050 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ All notable changes to this project will be documented in this file

### ⚠ BREAKING CHANGES

* removed `Structure` module
* removed `structure` module
* removed `book.translator` method, use `person.fullName` instead
* removed `book.isbn` method, use `commerce.isbn` instead
* removed `commerce.price` method, use `finance.amount` instead
* removed `commerce.productId` method, use `string.alphanumeric` instead
* removed `commerce.productRating` method, use `number.decimal` instead
* removed `commerce.discountAmount` method, use `number.decimal` instead
* removed `commerce.discountPercentage` method, use `number.decimal` instead
* removed `commerce.orderNumber` method, use `string.numeric` instead
* removed `commerce.discountCode` method, use `string.alphanumeric` instead
* removed `git.author` method, use `person.fullName` instead
* removed `helper.shuffle` method, use standard library shuffle instead
* removed `person.middleName` method, use `person.firstName` instead
* removed `weather.temperature` method, use `number.decimal` instead
* removed `weather.pressure` method, use `number.decimal` instead
* removed `weather.visibility` method, use `number.decimal` instead
* removed `weather.windSpeed` method, use `number.decimal` instead
* removed `weather.uvIndex` method, use `number.integer` instead
* removed `weather.humidity` method, use `number.integer` instead
* removed `weather.cloudCover` method, use `number.integer` instead

* changed std::string to std::string_view in where possible

### Features
Expand Down
22 changes: 0 additions & 22 deletions include/faker-cxx/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,6 @@ class Book
*/
static std::string_view publisher();

/**
* @brief Returns a random book ISBN.
*
* @returns Book ISBN.
*
* @code
* Book::isbn() // "978-83-01-00000-1"
* @endcode
*/
static std::string isbn();

/**
* @brief Returns the full name of a translator
*
* @returns std::string_view full name
*
* @code
* Book::translator() // "Eric Floyd"
* @endcode
*/
static std::string_view translator();

/**
* @brief Returns format of book
*
Expand Down
78 changes: 0 additions & 78 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ class Commerce
*/
static std::string_view department();

/**
* @brief Generates a random price between the given bounds (inclusive).
* @param min The lower bound for the price. Defaults to `0`.
* @param max The upper bound for the price. Defaults to `1000`.
*
* @code
* Commerce::price() // "88.62"
* @endcode
*/
static std::string price(double min = 0, double max = 1000);

/**
* @brief Generates a random sku by default only with digits.
*
Expand Down Expand Up @@ -130,17 +118,6 @@ class Commerce
*/
static std::string ISBN10();

/**
* @brief Returns a random product ID.
*
* @returns productId.
*
* @code
* Commerce::productId() // "ABCD123456"
* @endcode
*/
static std::string productId();

/**
* @brief Returns a random payment type.
*
Expand Down Expand Up @@ -196,17 +173,6 @@ class Commerce
*/
static std::string_view productReview();

/**
* @brief Returns a random product rating (0-5).
*
* @returns productRating.
*
* @code
* Commerce::productRating() // 4.1
* @endcode
*/
static double productRating();

/**
* @brief Returns a random discount type.
*
Expand All @@ -218,50 +184,6 @@ class Commerce
*/
static std::string_view discountType();

/**
* @brief Returns random discount code within the specified range of 6 to 12 characters.
*
* @returns discount code consists of uppercase letters and numbers.
*
* @code
* Commerce::discountCode() // "VNM15DEC1"
* @endcode
*/
static std::string discountCode();

/**
* @brief Returns a random discount amount within the specified range of 10 to 1000.
*
* @returns discountAmount.
*
* @code
* Commerce::discountAmount() // 57.80
* @endcode
*/
static double discountAmount();

/**
* @brief Returns a random discount percentage within the specified range of 1. to 90.
*
* @returns discountPercentage.
*
* @code
* Commerce::discountPercentage() // 35.50
* @endcode
*/
static double discountPercentage();

/**
* @brief Returns a random order number.
*
* @returns orderNumber.
*
* @code
* Commerce::orderNumber() // 0123456
* @endcode
*/
static std::string orderNumber();

/**
* @brief Returns a random order status.
*
Expand Down
13 changes: 0 additions & 13 deletions include/faker-cxx/Git.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,5 @@ class Git
* @endcode
*/
static std::string commitSha(unsigned length = 40);

/**
* @brief Returns a random author name and email.
*
* @param
*
* @returns Author.
*
* @code
* Git::author // {Author.name = "Rachel McLaughlin", Author.email = "[email protected]"}
* @endcode
*/
static Author author();
};
}
35 changes: 13 additions & 22 deletions include/faker-cxx/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ class Helper
static auto arrayElement(It start, It end) -> decltype(*::std::declval<It>())
{
size_t size = end - start;

if (size == 0)
{
throw std::invalid_argument{"Range [start,end) is empty."};
}

const auto index = Number::integer<size_t>(size - 1);
const std::integral auto index = Number::integer<size_t>(size - 1);

return start[index];
}

Expand Down Expand Up @@ -145,7 +147,9 @@ class Helper
}

T item;

std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator);

return item;
}

Expand Down Expand Up @@ -188,41 +192,26 @@ class Helper
}

const std::integral auto targetWeightValue = Number::integer<unsigned>(1, sumOfWeights);

unsigned currentSum = 0;

size_t currentIdx = 0;

while (currentIdx < data.size())
{
currentSum += data[currentIdx].weight;

if (currentSum >= targetWeightValue)
{
break;
}

currentIdx++;
}

return data.at(currentIdx).value;
}

/**
* @brief Returns shuffled vector.
*
* @tparam T an element type of the vector.
*
* @param data The vector.
*
* @return Vector with shuffled elements.
*
* @code
* Helper::shuffle<std::string>(std::vector<std::string>{{"hello"}, {"world"}}) // {{"world"}, {"hello"}}
* @endcode
*/
template <class T>
static std::vector<T> shuffle(std::vector<T> data)
{
std::shuffle(std::begin(data), std::end(data), pseudoRandomGenerator);

return data;
}

/**
* @brief Returns shuffled std::string
*
Expand Down Expand Up @@ -265,6 +254,7 @@ class Helper
}

std::vector<typename T::key_type> keys;

for (const auto& entry : object)
{
keys.push_back(entry.first);
Expand Down Expand Up @@ -296,6 +286,7 @@ class Helper
{
return callback();
}

return TResult();
}

Expand Down
15 changes: 0 additions & 15 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,6 @@ class Person
static std::string_view lastName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random middle name.
*
* @param country The local country. Defaults to `Country::England`.
* @param sex The optional sex to use.
*
* @returns Middle name starting with a capital letter.
*
* @code
* Person::middleName() // "Васильевич"
* @endcode
*/
static std::string_view middleName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random full name.
*
Expand Down
Loading

0 comments on commit c12f945

Please sign in to comment.