diff --git a/include/faker-cxx/Airline.h b/include/faker-cxx/Airline.h index 9af869a69..6f4240036 100644 --- a/include/faker-cxx/Airline.h +++ b/include/faker-cxx/Airline.h @@ -2,19 +2,13 @@ #include #include +#include "./types/AirlineTypes.h" namespace faker { class Airline { public: - enum class AircraftType - { - Regional, - Narrowbody, - Widebody, - }; - /** * @brief Get a random aircraft type * @@ -26,12 +20,6 @@ class Airline */ static std::string aircraftType(); - struct Airplane - { - std::string name; - std::string iataTypeCode; - }; - /** * @brief Get a random airplane * @@ -43,12 +31,6 @@ class Airline */ static Airplane airplane(); - struct AirlineStruct - { - std::string name; - std::string iataCode; - }; - /** * @brief Get a random airline * @@ -60,12 +42,6 @@ class Airline */ static AirlineStruct airline(); - struct Airport - { - std::string name; - std::string iataCode; - }; - /** * @brief Get a random airport * @@ -119,12 +95,6 @@ class Airline */ static std::string flightNumber(bool addLeadingZeros = false, unsigned int length = 4); - struct Range - { - unsigned int min; - unsigned int max; - }; - /** * @brief Get a random flight number from given length * diff --git a/include/faker-cxx/types/AirlineTypes.h b/include/faker-cxx/types/AirlineTypes.h new file mode 100644 index 000000000..9ee8c74a3 --- /dev/null +++ b/include/faker-cxx/types/AirlineTypes.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../Airline.h" +#include + +namespace faker { + enum class AircraftType + { + Regional, + Narrowbody, + Widebody, + }; + + struct Airplane + { + std::string name; + std::string iataTypeCode; + }; + + struct Airport + { + std::string name; + std::string iataCode; + }; + + + struct Range + { + unsigned int min; + unsigned int max; + }; + + struct AirlineStruct + { + std::string name; + std::string iataCode; + }; +} + diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index edb0a2e48..3316aae3e 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -18,22 +18,22 @@ std::string Airline::aircraftType() return Helper::arrayElement(aircraftTypes); } -Airline::Airplane Airline::airplane() +faker::Airplane Airline::airplane() { - return Helper::arrayElement(airplanes); + return Helper::arrayElement(airplanes); } -Airline::AirlineStruct Airline::airline() +faker::AirlineStruct Airline::airline() { - return Helper::arrayElement(airlines); + return Helper::arrayElement(airlines); } -Airline::Airport Airline::airport() +faker::Airport Airline::airport() { - return Helper::arrayElement(airports); + return Helper::arrayElement(airports); } -std::string Airline::seat(Airline::AircraftType aircraftType) +std::string Airline::seat(faker::AircraftType aircraftType) { return std::to_string(Number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + Helper::arrayElement(aircraftTypeSeatLetters.at(aircraftType)); @@ -59,7 +59,7 @@ std::string Airline::flightNumber(bool addLeadingZeros, unsigned int length) return String::numeric(length, false); } -std::string Airline::flightNumber(bool addLeadingZeros, Airline::Range length) +std::string Airline::flightNumber(bool addLeadingZeros, faker::Range length) { if (addLeadingZeros) { diff --git a/src/modules/airline/AirlineTest.cpp b/src/modules/airline/AirlineTest.cpp index c21170de8..8ec32d086 100644 --- a/src/modules/airline/AirlineTest.cpp +++ b/src/modules/airline/AirlineTest.cpp @@ -30,19 +30,19 @@ TEST_F(AirlineTest, shouldGenerateAircraftType) TEST_F(AirlineTest, shouldGenerateAirline) { - Airline::AirlineStruct generatedAirline = Airline::airline(); + faker::AirlineStruct generatedAirline = Airline::airline(); ASSERT_TRUE(std::ranges::any_of( - airlines, [generatedAirline](const Airline::AirlineStruct& airline) + airlines, [generatedAirline](const faker::AirlineStruct& airline) { return airline.name == generatedAirline.name && airline.iataCode == generatedAirline.iataCode; })); } TEST_F(AirlineTest, shouldGenerateAirplane) { - Airline::Airplane generatedAirplane = Airline::airplane(); + faker::Airplane generatedAirplane = Airline::airplane(); ASSERT_TRUE(std::ranges::any_of(airplanes, - [generatedAirplane](const Airline::Airplane& airplane) { + [generatedAirplane](const faker::Airplane& airplane) { return airplane.name == generatedAirplane.name && airplane.iataTypeCode == generatedAirplane.iataTypeCode; })); @@ -50,10 +50,10 @@ TEST_F(AirlineTest, shouldGenerateAirplane) TEST_F(AirlineTest, shouldGenerateAirport) { - Airline::Airport generatedAirport = Airline::airport(); + faker::Airport generatedAirport = Airline::airport(); ASSERT_TRUE(std::ranges::any_of( - airports, [generatedAirport](const Airline::Airport& airport) + airports, [generatedAirport](const faker::Airport& airport) { return airport.name == generatedAirport.name && airport.iataCode == generatedAirport.iataCode; })); } @@ -72,12 +72,12 @@ TEST_F(AirlineTest, shouldGenerateRecordLocator) TEST_F(AirlineTest, shouldGenerateSeatNumberRegional) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Regional); + std::string generatedSeatNumber = Airline::seat(faker::AircraftType::Regional); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); int min = 1; - int max = aircraftTypeMaxRows.at(Airline::AircraftType::Regional); + int max = aircraftTypeMaxRows.at(faker::AircraftType::Regional); bool inRange = false; for (int i = max; i >= min; --i) @@ -91,19 +91,19 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberRegional) } ASSERT_TRUE(inRange); - ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(Airline::AircraftType::Regional), + ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(faker::AircraftType::Regional), [generatedSeatNumber](char letter) { return generatedSeatNumber.back() == letter; })); } TEST_F(AirlineTest, shouldGenerateSeatNumberNarrowbody) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Narrowbody); + std::string generatedSeatNumber = Airline::seat(faker::AircraftType::Narrowbody); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); int min = 1; - int max = aircraftTypeMaxRows.at(Airline::AircraftType::Narrowbody); + int max = aircraftTypeMaxRows.at(faker::AircraftType::Narrowbody); bool inRange = false; for (int i = max; i >= min; --i) @@ -117,19 +117,19 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberNarrowbody) } ASSERT_TRUE(inRange); - ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(Airline::AircraftType::Narrowbody), + ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(faker::AircraftType::Narrowbody), [generatedSeatNumber](char letter) { return generatedSeatNumber.back() == letter; })); } TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Widebody); + std::string generatedSeatNumber = Airline::seat(faker::AircraftType::Widebody); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); int min = 1; - int max = aircraftTypeMaxRows.at(Airline::AircraftType::Widebody); + int max = aircraftTypeMaxRows.at(faker::AircraftType::Widebody); bool inRange = false; for (int i = max; i >= min; --i) @@ -143,7 +143,7 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) } ASSERT_TRUE(inRange); - ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(Airline::AircraftType::Widebody), + ASSERT_TRUE(std::ranges::any_of(aircraftTypeSeatLetters.at(faker::AircraftType::Widebody), [generatedSeatNumber](char letter) { return generatedSeatNumber.back() == letter; })); } diff --git a/src/modules/airline/data/Airlines.h b/src/modules/airline/data/Airlines.h index ea32eb57a..27e004c5c 100644 --- a/src/modules/airline/data/Airlines.h +++ b/src/modules/airline/data/Airlines.h @@ -7,7 +7,7 @@ namespace faker { -const std::vector airlines{ +const std::vector airlines{ {.name = "Aegean Airlines", .iataCode = "A3"}, {.name = "Aeroflot", .iataCode = "SU"}, {.name = "Aerolineas Argentinas", .iataCode = "AR"}, diff --git a/src/modules/airline/data/Airplanes.h b/src/modules/airline/data/Airplanes.h index 4666c5695..76efb7033 100644 --- a/src/modules/airline/data/Airplanes.h +++ b/src/modules/airline/data/Airplanes.h @@ -7,7 +7,7 @@ namespace faker { -const std::vector airplanes{ +const std::vector airplanes{ {.name = "Aerospatiale/BAC Concorde", .iataTypeCode = "SSC"}, {.name = "Airbus A300", .iataTypeCode = "AB3"}, {.name = "Airbus A310", .iataTypeCode = "310"}, diff --git a/src/modules/airline/data/Airports.h b/src/modules/airline/data/Airports.h index 5b1455be0..122bb729e 100644 --- a/src/modules/airline/data/Airports.h +++ b/src/modules/airline/data/Airports.h @@ -7,7 +7,7 @@ namespace faker { -const std::vector airports = { +const std::vector airports = { {.name = "Adelaide International Airport", .iataCode = "ADL"}, {.name = "Adolfo Suarez Madrid-Barajas Airport", .iataCode = "MAD"}, {.name = "Aeroparque Jorge Newbery Airport", .iataCode = "AEP"}, diff --git a/src/modules/airline/data/Seat.h b/src/modules/airline/data/Seat.h index 8fd34db15..708fbdf0c 100644 --- a/src/modules/airline/data/Seat.h +++ b/src/modules/airline/data/Seat.h @@ -9,16 +9,16 @@ namespace faker { -const std::unordered_map aircraftTypeMaxRows = { - {Airline::AircraftType::Regional, 20}, - {Airline::AircraftType::Narrowbody, 40}, - {Airline::AircraftType::Widebody, 60}, +const std::unordered_map aircraftTypeMaxRows = { + {faker::AircraftType::Regional, 20}, + {faker::AircraftType::Narrowbody, 40}, + {faker::AircraftType::Widebody, 60}, }; -const std::unordered_map> aircraftTypeSeatLetters = { - {Airline::AircraftType::Regional, {'A', 'B', 'C', 'D'}}, - {Airline::AircraftType::Narrowbody, {'A', 'B', 'C', 'D', 'E', 'F'}}, - {Airline::AircraftType::Widebody, {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K'}}, +const std::unordered_map> aircraftTypeSeatLetters = { + {faker::AircraftType::Regional, {'A', 'B', 'C', 'D'}}, + {faker::AircraftType::Narrowbody, {'A', 'B', 'C', 'D', 'E', 'F'}}, + {faker::AircraftType::Widebody, {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K'}}, }; } diff --git a/src/modules/structure/Structure.cpp b/src/modules/structure/Structure.cpp index 50e3f3d9e..b5f2a48bd 100644 --- a/src/modules/structure/Structure.cpp +++ b/src/modules/structure/Structure.cpp @@ -43,7 +43,7 @@ const std::map> moduleFuncti {faker::StructureToken::AirlineAirlineCode, []() { return faker::Airline::airline().iataCode; }}, {faker::StructureToken::AirlineAirportName, []() { return faker::Airline::airport().name; }}, {faker::StructureToken::AirlineAirportCode, []() { return faker::Airline::airport().iataCode; }}, - {faker::StructureToken::AirlineSeat, []() { return faker::Airline::seat(faker::Airline::AircraftType()); }}, + {faker::StructureToken::AirlineSeat, []() { return faker::Airline::seat(faker::AircraftType()); }}, {faker::StructureToken::AirlineRecordLocator, []() { return faker::Airline::recordLocator(); }}, {faker::StructureToken::AirlineFlightNumber, []() { return faker::Airline::flightNumber(false, 4); }}, diff --git a/src/modules/structure/StructureTest.cpp b/src/modules/structure/StructureTest.cpp index e1293f6a5..1e0a2a545 100644 --- a/src/modules/structure/StructureTest.cpp +++ b/src/modules/structure/StructureTest.cpp @@ -48,7 +48,7 @@ TEST_F(StructureTest, shouldGenerateJson) ASSERT_EQ(key4, "Actor name"); ASSERT_TRUE( - std::ranges::any_of(airports, [value1](const Airline::Airport& airport) { return airport.name == value1; })); + std::ranges::any_of(airports, [value1](const faker::Airport& airport) { return airport.name == value1; })); ASSERT_TRUE(std::ranges::any_of(birds, [value2](const std::string& bird) { return bird == value2; })); ASSERT_TRUE(std::ranges::any_of(titles, [value3](const std::string& title) { return title == value3; })); ASSERT_TRUE(std::ranges::any_of(actors, [value4](const std::string& actor) { return actor == value4; })); @@ -80,7 +80,7 @@ TEST_F(StructureTest, shouldGenerateCSV) { ASSERT_TRUE(std::ranges::any_of(actors, [&line](const std::string& actor) { return line.find(actor) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(airports, [&line](const Airline::Airport& airport) + ASSERT_TRUE(std::ranges::any_of(airports, [&line](const faker::Airport& airport) { return line.find(airport.name) != std::string::npos; })); ASSERT_TRUE(std::ranges::any_of(birds, [&line](const std::string& bird) { return line.find(bird) != std::string::npos; }));