diff --git a/CHANGELOG.md b/CHANGELOG.md index 67c5e3ba1..05a98abfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/include/faker-cxx/Vehicle.h b/include/faker-cxx/Vehicle.h index 17e2c1368..c92e77383 100644 --- a/include/faker-cxx/Vehicle.h +++ b/include/faker-cxx/Vehicle.h @@ -2,21 +2,18 @@ #include -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. @@ -24,10 +21,10 @@ class Vehicle * @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. @@ -35,10 +32,10 @@ class Vehicle * @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. @@ -46,10 +43,10 @@ class Vehicle * @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. @@ -57,10 +54,10 @@ class Vehicle * @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. @@ -68,10 +65,10 @@ class Vehicle * @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). @@ -79,10 +76,10 @@ class Vehicle * @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). @@ -90,10 +87,10 @@ class Vehicle * @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). @@ -101,9 +98,8 @@ class Vehicle * @returns vehicle registration number. * * @code - * Vehicle::vrm() // "MF56UPA" + * vehicle::vrm() // "MF56UPA" * @endcode */ - static std::string vrm(); -}; + std::string vrm(); } diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index e7c27950d..b2a12837e 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -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"}; @@ -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)); diff --git a/src/modules/vehicle/VehicleData.h b/src/modules/vehicle/VehicleData.h index e87b8b28c..fa06c9289 100644 --- a/src/modules/vehicle/VehicleData.h +++ b/src/modules/vehicle/VehicleData.h @@ -3,9 +3,7 @@ #include #include -namespace faker -{ -namespace vehicle +namespace faker::vehicle { const auto bicycle_types = std::to_array({ "BMX bike", "Cargo bike", "City bike", "Electric bike", "Folding bike", @@ -39,4 +37,3 @@ const auto vehicle_types = std::to_array({ }); } -} diff --git a/tests/modules/vehicle/VehicleTest.cpp b/tests/modules/vehicle/VehicleTest.cpp index c1eac7652..0ef0e84fd 100644 --- a/tests/modules/vehicle/VehicleTest.cpp +++ b/tests/modules/vehicle/VehicleTest.cpp @@ -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}"); @@ -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}");