Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: vehicle module migrate #720

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All notable changes to this project will be documented in this file
* changed classes to namespaces for functions grouping, for example use `number::integer` instead of `Number::integer`, applies to all modules
* changed std::string to std::string_view in functions where is was possible
* changed function name from `sport` to `sportName` in sport module
* changed function name from `vehicle` to `vehicleName` in vehicle module

### Features

Expand Down
42 changes: 19 additions & 23 deletions include/faker-cxx/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,104 @@

#include <string_view>

namespace faker
namespace faker::vehicle
{
class Vehicle
{
public:
/**
* @brief Returns a random bicycle type.
*
* @returns bicycle type.
*
* @code
* Vehicle::bicycle() // "Electric bike"
* vehicle::bicycle() // "Electric bike"
* @endcode
*/
static std::string_view bicycle();
std::string_view bicycle();

/**
* @brief Returns a random vehicle color.
*
* @returns vehicle color.
*
* @code
* Vehicle::color() // "Silver"
* vehicle::color() // "Silver"
* @endcode
*/
static std::string_view color();
std::string_view color();

/**
* @brief Returns a random vehicle fuel.
*
* @returns vehicle fuel.
*
* @code
* Vehicle::fuel() // "Diesel"
* vehicle::fuel() // "Diesel"
* @endcode
*/
static std::string_view fuel();
std::string_view fuel();

/**
* @brief Returns a random vehicle(car) manufacturer.
*
* @returns vehicle(car) manufacturer.
*
* @code
* Vehicle::manufacturer() // "Ferrari"
* vehicle::manufacturer() // "Ferrari"
* @endcode
*/
static std::string_view manufacturer();
std::string_view manufacturer();

/**
* @brief Returns a random vehicle(car) model.
*
* @returns vehicle(car) model.
*
* @code
* Vehicle::model() // "Fiesta"
* vehicle::model() // "Fiesta"
* @endcode
*/
static std::string_view model();
std::string_view model();

/**
* @brief Returns a random vehicle type.
*
* @returns vehicle type.
*
* @code
* Vehicle::type() // "Van"
* vehicle::type() // "Van"
* @endcode
*/
static std::string_view type();
std::string_view type();

/**
* @brief Returns a random vehicle(car).
*
* @returns vehicle composed by a manufacturer and model.
*
* @code
* Vehicle::vehicle() // "BMW Explorer"
* vehicle::vehicleName() // "BMW Explorer"
* @endcode
*/
static std::string vehicle();
std::string vehicleName();

/**
* @brief Returns a vehicle identification number (VIN).
*
* @returns vehicle identification number.
*
* @code
* Vehicle::vin() // "YV1MH682762184654"
* vehicle::vin() // "YV1MH682762184654"
* @endcode
*/
static std::string vin();
std::string vin();

/**
* @brief Returns a vehicle registration number (Vehicle Registration Mark - VRM).
*
* @returns vehicle registration number.
*
* @code
* Vehicle::vrm() // "MF56UPA"
* vehicle::vrm() // "MF56UPA"
* @endcode
*/
static std::string vrm();
};
std::string vrm();
}
32 changes: 16 additions & 16 deletions src/modules/vehicle/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@
#include "faker-cxx/String.h"
#include "VehicleData.h"

namespace faker
namespace faker::vehicle
{

std::string_view Vehicle::bicycle()
std::string_view bicycle()
{
return Helper::arrayElement(vehicle::bicycle_types);
return Helper::arrayElement(bicycle_types);
}

std::string_view Vehicle::color()
std::string_view color()
{
return Helper::arrayElement(vehicle::vehicle_colors);
return Helper::arrayElement(vehicle_colors);
}

std::string_view Vehicle::fuel()
std::string_view fuel()
{
return Helper::arrayElement(vehicle::fuel_types);
return Helper::arrayElement(fuel_types);
}

std::string_view Vehicle::manufacturer()
std::string_view manufacturer()
{
return Helper::arrayElement(vehicle::manufacturers);
return Helper::arrayElement(manufacturers);
}

std::string_view Vehicle::model()
std::string_view model()
{
return Helper::arrayElement(vehicle::models);
return Helper::arrayElement(models);
}

std::string_view Vehicle::type()
std::string_view type()
{
return Helper::arrayElement(vehicle::vehicle_types);
return Helper::arrayElement(vehicle_types);
}

std::string Vehicle::vehicle()
std::string vehicleName()
{
return FormatHelper::format("{} {}", manufacturer(), model());
}

std::string Vehicle::vin()
std::string vin()
{
std::string exclude_characters{"oiqOIQ"};

Expand All @@ -57,7 +57,7 @@ std::string Vehicle::vin()
Number::integer(10000, 99999));
}

std::string Vehicle::vrm()
std::string vrm()
{
return FormatHelper::format("{}{}{}", String::alpha(2, StringCasing::Upper), String::numeric(2, true),
String::alpha(3, StringCasing::Upper));
Expand Down
5 changes: 1 addition & 4 deletions src/modules/vehicle/VehicleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <array>
#include <string_view>

namespace faker
{
namespace vehicle
namespace faker::vehicle
{
const auto bicycle_types = std::to_array<std::string_view>({
"BMX bike", "Cargo bike", "City bike", "Electric bike", "Folding bike",
Expand Down Expand Up @@ -39,4 +37,3 @@ const auto vehicle_types = std::to_array<std::string_view>({
});

}
}
34 changes: 17 additions & 17 deletions tests/modules/vehicle/VehicleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,67 @@ class VehicleTest : public Test

TEST_F(VehicleTest, shouldGenerateBicycle)
{
const auto generatedBicycle = Vehicle::bicycle();
const auto generatedBicycle = bicycle();

ASSERT_TRUE(std::ranges::any_of(vehicle::bicycle_types, [generatedBicycle](const std::string_view& bicycle)
ASSERT_TRUE(std::ranges::any_of(bicycle_types, [generatedBicycle](const std::string_view& bicycle)
{ return bicycle == generatedBicycle; }));
}

TEST_F(VehicleTest, shouldGenerateColor)
{
const auto generatedColor = Vehicle::color();
const auto generatedColor = color();

ASSERT_TRUE(std::ranges::any_of(vehicle::vehicle_colors, [generatedColor](const std::string_view& color)
ASSERT_TRUE(std::ranges::any_of(vehicle_colors, [generatedColor](const std::string_view& color)
{ return color == generatedColor; }));
}

TEST_F(VehicleTest, shouldGenerateFuel)
{
const auto generatedFuel = Vehicle::fuel();
const auto generatedFuel = fuel();

ASSERT_TRUE(std::ranges::any_of(vehicle::fuel_types,
ASSERT_TRUE(std::ranges::any_of(fuel_types,
[generatedFuel](const std::string_view& fuel) { return fuel == generatedFuel; }));
}

TEST_F(VehicleTest, shouldGenerateManufacturer)
{
const auto generatedManufacturer = Vehicle::manufacturer();
const auto generatedManufacturer = manufacturer();

ASSERT_TRUE(std::ranges::any_of(vehicle::manufacturers,
ASSERT_TRUE(std::ranges::any_of(manufacturers,
[generatedManufacturer](const std::string_view& manufacturer)
{ return manufacturer == generatedManufacturer; }));
}

TEST_F(VehicleTest, shouldGenerateModel)
{
const auto generatedModel = Vehicle::model();
const auto generatedModel = model();

ASSERT_TRUE(std::ranges::any_of(vehicle::models, [generatedModel](const std::string_view& model)
ASSERT_TRUE(std::ranges::any_of(models, [generatedModel](const std::string_view& model)
{ return model == generatedModel; }));
}

TEST_F(VehicleTest, shouldGenerateType)
{
const auto generatedType = Vehicle::type();
const auto generatedType = type();

ASSERT_TRUE(std::ranges::any_of(vehicle::vehicle_types,
ASSERT_TRUE(std::ranges::any_of(vehicle_types,
[generatedType](const std::string_view& type) { return type == generatedType; }));
}

TEST_F(VehicleTest, shouldGenerateVehicle)
{
const auto generatedVehicle = Vehicle::vehicle();
const auto generatedVehicle = vehicleName();

ASSERT_TRUE(std::ranges::any_of(vehicle::manufacturers, [generatedVehicle](const std::string_view& manufacturer)
ASSERT_TRUE(std::ranges::any_of(manufacturers, [generatedVehicle](const std::string_view& manufacturer)
{ return generatedVehicle.starts_with(manufacturer); }));

ASSERT_TRUE(std::ranges::any_of(vehicle::models, [generatedVehicle](const std::string_view& model)
ASSERT_TRUE(std::ranges::any_of(models, [generatedVehicle](const std::string_view& model)
{ return generatedVehicle.ends_with(model); }));
}

TEST_F(VehicleTest, shouldGenerateVin)
{
const auto generatedVin = Vehicle::vin();
const auto generatedVin = vin();

std::regex vinRegex("[A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[0-9]{5}");

Expand All @@ -91,7 +91,7 @@ TEST_F(VehicleTest, shouldGenerateVin)

TEST_F(VehicleTest, shouldGenerateVrm)
{
const auto generatedVrm = Vehicle::vrm();
const auto generatedVrm = vrm();

std::regex vrmRegex("[A-Z]{2}[0-9]{2}[A-Z]{3}");

Expand Down
Loading