From dc973bdff6ad1a5bb02567e7d4aef13676deee93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blar?= Date: Fri, 24 May 2024 18:47:39 +0200 Subject: [PATCH] refactor airline data (#552) * refactor airline data * fix tests --- CMakeLists.txt | 40 +- include/faker-cxx/Airline.h | 16 +- include/faker-cxx/Helper.h | 14 + src/common/FormatHelper.cpp | 5 +- .../precisionMapper => }/PrecisionMapper.cpp | 0 .../precisionMapper => }/PrecisionMapper.h | 0 .../errors/TokenGeneratorNotFoundError.h | 11 - src/modules/airline/Airline.cpp | 16 +- src/modules/airline/AirlineData.cpp | 444 ++++++++++++++++++ src/modules/airline/AirlineData.h | 16 + src/modules/airline/data/AircraftTypes.h | 9 - src/modules/airline/data/Airlines.h | 137 ------ src/modules/airline/data/Airplanes.h | 167 ------- src/modules/airline/data/Airports.h | 148 ------ src/modules/airline/data/Seat.h | 22 - src/modules/finance/Finance.cpp | 2 +- src/modules/location/Location.cpp | 64 +-- tests/CMakeLists.txt | 2 +- tests/common/FormatHelperTest.cpp | 4 +- .../PrecisionMapperTest.cpp | 2 +- tests/modules/airline/AirlineTest.cpp | 49 +- 21 files changed, 563 insertions(+), 605 deletions(-) rename src/common/{mappers/precisionMapper => }/PrecisionMapper.cpp (100%) rename src/common/{mappers/precisionMapper => }/PrecisionMapper.h (100%) delete mode 100644 src/common/errors/TokenGeneratorNotFoundError.h create mode 100644 src/modules/airline/AirlineData.cpp create mode 100644 src/modules/airline/AirlineData.h delete mode 100644 src/modules/airline/data/AircraftTypes.h delete mode 100644 src/modules/airline/data/Airlines.h delete mode 100644 src/modules/airline/data/Airplanes.h delete mode 100644 src/modules/airline/data/Airports.h delete mode 100644 src/modules/airline/data/Seat.h rename tests/common/{mappers/precisionMapper => }/PrecisionMapperTest.cpp (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c8664486..08a11a366 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,44 +17,46 @@ endif () set(LIBRARY_NAME faker-cxx) set(FAKER_SOURCES + src/modules/airline/Airline.cpp + src/modules/airline/AirlineData.cpp src/modules/animal/Animal.cpp src/modules/book/Book.cpp src/modules/color/Color.cpp src/modules/commerce/Commerce.cpp src/modules/company/Company.cpp + src/modules/computer/Computer.cpp + src/modules/crypto/Crypto.cpp + src/modules/database/Database.cpp src/modules/datatype/Datatype.cpp src/modules/date/Date.cpp src/modules/finance/Finance.cpp src/modules/food/Food.cpp + src/modules/git/Git.cpp + src/modules/hacker/Hacker.cpp src/modules/helper/Helper.cpp + src/modules/image/Image.cpp src/modules/internet/Internet.cpp src/modules/location/Location.cpp src/modules/lorem/Lorem.cpp + src/modules/medicine/Medicine.cpp + src/modules/movie/Movie.cpp + src/modules/music/Music.cpp src/modules/number/Number.cpp src/modules/person/Person.cpp - src/modules/string/String.cpp - src/modules/word/Word.cpp src/modules/phone/Phone.cpp - src/common/StringHelper.cpp - src/common/FormatHelper.cpp - src/common/LuhnCheck.cpp - src/common/mappers/precisionMapper/PrecisionMapper.cpp - src/modules/system/System.cpp - src/modules/database/Database.cpp - src/modules/music/Music.cpp - src/modules/movie/Movie.cpp - src/modules/git/Git.cpp - src/modules/hacker/Hacker.cpp + src/modules/science/Science.cpp src/modules/sport/Sport.cpp + src/modules/string/String.cpp + src/modules/system/System.cpp + src/modules/vehicle/Vehicle.cpp src/modules/videoGame/VideoGame.cpp - src/modules/medicine/Medicine.cpp src/modules/weather/Weather.cpp - src/modules/airline/Airline.cpp - src/modules/image/Image.cpp - src/modules/crypto/Crypto.cpp - src/modules/computer/Computer.cpp - src/modules/vehicle/Vehicle.cpp - src/modules/science/Science.cpp + src/modules/word/Word.cpp + + src/common/FormatHelper.cpp + src/common/LuhnCheck.cpp + src/common/StringHelper.cpp + src/common/PrecisionMapper.cpp ) add_library(${LIBRARY_NAME} ${FAKER_SOURCES}) diff --git a/include/faker-cxx/Airline.h b/include/faker-cxx/Airline.h index 3f45b0921..9ecfb4dee 100644 --- a/include/faker-cxx/Airline.h +++ b/include/faker-cxx/Airline.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace faker { @@ -16,12 +16,12 @@ class Airline * Airline::aircraftType // "narrowbody" * @endcode */ - static std::string aircraftType(); + static std::string_view aircraftType(); struct Airplane { - std::string name; - std::string iataTypeCode; + std::string_view name; + std::string_view iataTypeCode; }; /** @@ -37,8 +37,8 @@ class Airline struct AirlineInfo { - std::string name; - std::string iataCode; + std::string_view name; + std::string_view iataCode; }; /** @@ -54,8 +54,8 @@ class Airline struct Airport { - std::string name; - std::string iataCode; + std::string_view name; + std::string_view iataCode; }; /** diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h index 51d5eab1a..8010ababe 100644 --- a/include/faker-cxx/Helper.h +++ b/include/faker-cxx/Helper.h @@ -42,6 +42,19 @@ class Helper return data[index]; } + template + static T arrayElement(const std::array& data) + { + if (data.empty()) + { + throw std::invalid_argument{"Data is empty."}; + } + + const auto index = Number::integer(data.size() - 1); + + return data[index]; + } + /** * @brief Get a random element from a vector. * @@ -89,6 +102,7 @@ class Helper { throw std::invalid_argument{"Data is empty."}; } + T item; std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator); return item; diff --git a/src/common/FormatHelper.cpp b/src/common/FormatHelper.cpp index 75b48ab7f..ce8ae419e 100644 --- a/src/common/FormatHelper.cpp +++ b/src/common/FormatHelper.cpp @@ -1,6 +1,6 @@ #include "FormatHelper.h" -#include "errors/TokenGeneratorNotFoundError.h" +#include namespace faker { @@ -26,8 +26,7 @@ std::string FormatHelper::fillTokenValues(const std::string& format, if (foundTokenGenerator == tokenValueGenerators.end()) { - throw errors::TokenGeneratorNotFoundError{ - FormatHelper::format("Generator not found for token {}.", token)}; + throw std::runtime_error{FormatHelper::format("Generator not found for token {}.", token)}; } filledFormat += foundTokenGenerator->second(); diff --git a/src/common/mappers/precisionMapper/PrecisionMapper.cpp b/src/common/PrecisionMapper.cpp similarity index 100% rename from src/common/mappers/precisionMapper/PrecisionMapper.cpp rename to src/common/PrecisionMapper.cpp diff --git a/src/common/mappers/precisionMapper/PrecisionMapper.h b/src/common/PrecisionMapper.h similarity index 100% rename from src/common/mappers/precisionMapper/PrecisionMapper.h rename to src/common/PrecisionMapper.h diff --git a/src/common/errors/TokenGeneratorNotFoundError.h b/src/common/errors/TokenGeneratorNotFoundError.h deleted file mode 100644 index 4cd77217d..000000000 --- a/src/common/errors/TokenGeneratorNotFoundError.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace faker::errors -{ -struct TokenGeneratorNotFoundError : std::runtime_error -{ - using std::runtime_error::runtime_error; -}; -} diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 4ade7e898..e2de0ac66 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -1,34 +1,30 @@ #include "faker-cxx/Airline.h" -#include "data/AircraftTypes.h" -#include "data/Airlines.h" -#include "data/Airplanes.h" -#include "data/Airports.h" -#include "data/Seat.h" +#include "AirlineData.h" #include "faker-cxx/Helper.h" #include "faker-cxx/Number.h" #include "faker-cxx/String.h" namespace faker { -std::string Airline::aircraftType() +std::string_view Airline::aircraftType() { - return Helper::arrayElement(aircraftTypes); + return Helper::arrayElement(aircraftTypes); } Airline::Airplane Airline::airplane() { - return Helper::arrayElement(airplanes); + return Helper::arrayElement(airplanes); } Airline::AirlineInfo Airline::airline() { - return Helper::arrayElement(airlines); + return Helper::arrayElement(airlines); } Airline::Airport Airline::airport() { - return Helper::arrayElement(airports); + return Helper::arrayElement(airports); } std::string Airline::seat(Airline::AircraftType aircraftType) diff --git a/src/modules/airline/AirlineData.cpp b/src/modules/airline/AirlineData.cpp new file mode 100644 index 000000000..964f4c531 --- /dev/null +++ b/src/modules/airline/AirlineData.cpp @@ -0,0 +1,444 @@ +#include "AirlineData.h" + +namespace faker +{ +const std::array aircraftTypes = {"regional", "narrowbody", "widebody"}; + +const std::array airlines = {{ + {"Aegean Airlines", "A3"}, + {"Aeroflot", "SU"}, + {"Aerolineas Argentinas", "AR"}, + {"Aeromexico", "AM"}, + {"Air Algerie", "AH"}, + {"Air Arabia", "G9"}, + {"Air Canada", "AC"}, + {"Air China", "CA"}, + {"Air Europa", "UX"}, + {"Air France-KLM", "AF"}, + {"Air India", "AI"}, + {"Air Mauritius", "MK"}, + {"Air New Zealand", "NZ"}, + {"Air Niugini", "PX"}, + {"Air Tahiti", "VT"}, + {"Air Tahiti Nui", "TN"}, + {"Air Transat", "TS"}, + {"AirAsia X", "D7"}, + {"AirAsia", "AK"}, + {"Aircalin", "SB"}, + {"Alaska Airlines", "AS"}, + {"Alitalia", "AZ"}, + {"All Nippon Airways", "NH"}, + {"Allegiant Air", "G4"}, + {"American Airlines", "AA"}, + {"Asiana Airlines", "OZ"}, + {"Avianca", "AV"}, + {"Azul Linhas Aereas Brasileiras", "AD"}, + {"Azur Air", "ZF"}, + {"Beijing Capital Airlines", "JD"}, + {"Boliviana de Aviacion", "OB"}, + {"British Airways", "BA"}, + {"Cathay Pacific", "CX"}, + {"Cebu Pacific Air", "5J"}, + {"China Airlines", "CI"}, + {"China Eastern Airlines", "MU"}, + {"China Southern Airlines", "CZ"}, + {"Condor", "DE"}, + {"Copa Airlines", "CM"}, + {"Delta Air Lines", "DL"}, + {"Easyfly", "VE"}, + {"EasyJet", "U2"}, + {"EcoJet", "8J"}, + {"Egyptair", "MS"}, + {"El Al", "LY"}, + {"Emirates Airlines", "EK"}, + {"Ethiopian Airlines", "ET"}, + {"Etihad Airways", "EY"}, + {"EVA Air", "BR"}, + {"Fiji Airways", "FJ"}, + {"Finnair", "AY"}, + {"Flybondi", "FO"}, + {"Flydubai", "FZ"}, + {"FlySafair", "FA"}, + {"Frontier Airlines", "F9"}, + {"Garuda Indonesia", "GA"}, + {"Go First", "G8"}, + {"Gol Linhas Aereas Inteligentes", "G3"}, + {"Hainan Airlines", "HU"}, + {"Hawaiian Airlines", "HA"}, + {"IndiGo Airlines", "6E"}, + {"Japan Airlines", "JL"}, + {"Jeju Air", "7C"}, + {"Jet2", "LS"}, + {"JetBlue Airways", "B6"}, + {"JetSMART", "JA"}, + {"Juneyao Airlines", "HO"}, + {"Kenya Airways", "KQ"}, + {"Korean Air", "KE"}, + {"Kulula.com", "MN"}, + {"LATAM Airlines", "LA"}, + {"Lion Air", "JT"}, + {"LOT Polish Airlines", "LO"}, + {"Lufthansa", "LH"}, + {"Libyan Airlines", "LN"}, + {"Linea Aerea Amaszonas", "Z8"}, + {"Malaysia Airlines", "MH"}, + {"Nordwind Airlines", "N4"}, + {"Norwegian Air Shuttle", "DY"}, + {"Oman Air", "WY"}, + {"Pakistan International Airlines", "PK"}, + {"Pegasus Airlines", "PC"}, + {"Philippine Airlines", "PR"}, + {"Qantas Group", "QF"}, + {"Qatar Airways", "QR"}, + {"Republic Airways", "YX"}, + {"Royal Air Maroc", "AT"}, + {"Ryanair", "FR"}, + {"S7 Airlines", "S7"}, + {"SAS", "SK"}, + {"Satena", "9R"}, + {"Saudia", "SV"}, + {"Shandong Airlines", "SC"}, + {"Sichuan Airlines", "3U"}, + {"Singapore Airlines", "SQ"}, + {"Sky Airline", "H2"}, + {"SkyWest Airlines", "OO"}, + {"South African Airways", "SA"}, + {"Southwest Airlines", "WN"}, + {"SpiceJet", "SG"}, + {"Spirit Airlines", "NK"}, + {"Spring Airlines", "9S"}, + {"SriLankan Airlines", "UL"}, + {"Star Peru", "2I"}, + {"Sun Country Airlines", "SY"}, + {"SunExpress", "XQ"}, + {"TAP Air Portugal", "TP"}, + {"Thai AirAsia", "FD"}, + {"Thai Airways", "TG"}, + {"TUI Airways", "BY"}, + {"Tunisair", "TU"}, + {"Turkish Airlines", "TK"}, + {"Ukraine International", "PS"}, + {"United Airlines", "UA"}, + {"Ural Airlines", "U6"}, + {"VietJet Air", "VJ"}, + {"Vietnam Airlines", "VN"}, + {"Virgin Atlantic Airways", "VS"}, + {"Virgin Australia", "VA"}, + {"VivaAerobus", "VB"}, + {"VOEPASS Linhas Aereas", "2Z"}, + {"Volaris", "Y4"}, + {"WestJet", "WS"}, + {"Wingo", "P5"}, + {"Wizz Air", "W6"}, +}}; + +const std::array airplanes{{ + {"Aerospatiale/BAC Concorde", "SSC"}, + {"Airbus A300", "AB3"}, + {"Airbus A310", "310"}, + {"Airbus A310-200", "312"}, + {"Airbus A310-300", "313"}, + {"Airbus A318", "318"}, + {"Airbus A319", "319"}, + {"Airbus A319neo", "31N"}, + {"Airbus A320", "320"}, + {"Airbus A320neo", "32N"}, + {"Airbus A321", "321"}, + {"Airbus A321neo", "32Q"}, + {"Airbus A330", "330"}, + {"Airbus A330-200", "332"}, + {"Airbus A330-300", "333"}, + {"Airbus A330-800neo", "338"}, + {"Airbus A330-900neo", "339"}, + {"Airbus A340", "340"}, + {"Airbus A340-200", "342"}, + {"Airbus A340-300", "343"}, + {"Airbus A340-500", "345"}, + {"Airbus A340-600", "346"}, + {"Airbus A350", "350"}, + {"Airbus A350-900", "359"}, + {"Airbus A350-1000", "351"}, + {"Airbus A380", "380"}, + {"Airbus A380-800", "388"}, + {"Antonov An-12", "ANF"}, + {"Antonov An-24", "AN4"}, + {"Antonov An-26", "A26"}, + {"Antonov An-28", "A28"}, + {"Antonov An-30", "A30"}, + {"Antonov An-32", "A32"}, + {"Antonov An-72", "AN7"}, + {"Antonov An-124 Ruslan", "A4F"}, + {"Antonov An-140", "A40"}, + {"Antonov An-148", "A81"}, + {"Antonov An-158", "A58"}, + {"Antonov An-225 Mriya", "A5F"}, + {"Boeing 707", "703"}, + {"Boeing 717", "717"}, + {"Boeing 720B", "B72"}, + {"Boeing 727", "727"}, + {"Boeing 727-100", "721"}, + {"Boeing 727-200", "722"}, + {"Boeing 737 MAX 7", "7M7"}, + {"Boeing 737 MAX 8", "7M8"}, + {"Boeing 737 MAX 9", "7M9"}, + {"Boeing 737 MAX 10", "7MJ"}, + {"Boeing 737", "737"}, + {"Boeing 737-100", "731"}, + {"Boeing 737-200", "732"}, + {"Boeing 737-300", "733"}, + {"Boeing 737-400", "734"}, + {"Boeing 737-500", "735"}, + {"Boeing 737-600", "736"}, + {"Boeing 737-700", "73G"}, + {"Boeing 737-800", "738"}, + {"Boeing 737-900", "739"}, + {"Boeing 747", "747"}, + {"Boeing 747-100", "741"}, + {"Boeing 747-200", "742"}, + {"Boeing 747-300", "743"}, + {"Boeing 747-400", "744"}, + {"Boeing 747-400D", "74J"}, + {"Boeing 747-8", "748"}, + {"Boeing 747SP", "74L"}, + {"Boeing 747SR", "74R"}, + {"Boeing 757", "757"}, + {"Boeing 757-200", "752"}, + {"Boeing 757-300", "753"}, + {"Boeing 767", "767"}, + {"Boeing 767-200", "762"}, + {"Boeing 767-300", "763"}, + {"Boeing 767-400", "764"}, + {"Boeing 777", "777"}, + {"Boeing 777-200", "772"}, + {"Boeing 777-200LR", "77L"}, + {"Boeing 777-300", "773"}, + {"Boeing 777-300ER", "77W"}, + {"Boeing 787", "787"}, + {"Boeing 787-8", "788"}, + {"Boeing 787-9", "789"}, + {"Boeing 787-10", "781"}, + {"Canadair Challenger", "CCJ"}, + {"Canadair CL-44", "CL4"}, + {"Canadair Regional Jet 100", "CR1"}, + {"Canadair Regional Jet 200", "CR2"}, + {"Canadair Regional Jet 700", "CR7"}, + {"Canadair Regional Jet 705", "CRA"}, + {"Canadair Regional Jet 900", "CR9"}, + {"Canadair Regional Jet 1000", "CRK"}, + {"De Havilland Canada DHC-2 Beaver", "DHP"}, + {"De Havilland Canada DHC-2 Turbo-Beaver", "DHR"}, + {"De Havilland Canada DHC-3 Otter", "DHL"}, + {"De Havilland Canada DHC-4 Caribou", "DHC"}, + {"De Havilland Canada DHC-6 Twin Otter", "DHT"}, + {"De Havilland Canada DHC-7 Dash 7", "DH7"}, + {"De Havilland Canada DHC-8-100 Dash 8 / 8Q", "DH1"}, + {"De Havilland Canada DHC-8-200 Dash 8 / 8Q", "DH2"}, + {"De Havilland Canada DHC-8-300 Dash 8 / 8Q", "DH3"}, + {"De Havilland Canada DHC-8-400 Dash 8Q", "DH4"}, + {"De Havilland DH.104 Dove", "DHD"}, + {"De Havilland DH.114 Heron", "DHH"}, + {"Douglas DC-3", "D3F"}, + {"Douglas DC-6", "D6F"}, + {"Douglas DC-8-50", "D8T"}, + {"Douglas DC-8-62", "D8L"}, + {"Douglas DC-8-72", "D8Q"}, + {"Douglas DC-9-10", "D91"}, + {"Douglas DC-9-20", "D92"}, + {"Douglas DC-9-30", "D93"}, + {"Douglas DC-9-40", "D94"}, + {"Douglas DC-9-50", "D95"}, + {"Douglas DC-10", "D10"}, + {"Douglas DC-10-10", "D1X"}, + {"Douglas DC-10-30", "D1Y"}, + {"Embraer 170", "E70"}, + {"Embraer 175", "E75"}, + {"Embraer 190", "E90"}, + {"Embraer 195", "E95"}, + {"Embraer E190-E2", "290"}, + {"Embraer E195-E2", "295"}, + {"Embraer EMB.110 Bandeirante", "EMB"}, + {"Embraer EMB.120 Brasilia", "EM2"}, + {"Embraer Legacy 600", "ER3"}, + {"Embraer Phenom 100", "EP1"}, + {"Embraer Phenom 300", "EP3"}, + {"Embraer RJ135", "ER3"}, + {"Embraer RJ140", "ERD"}, + {"Embraer RJ145 Amazon", "ER4"}, + {"Ilyushin IL18", "IL8"}, + {"Ilyushin IL62", "IL6"}, + {"Ilyushin IL76", "IL7"}, + {"Ilyushin IL86", "ILW"}, + {"Ilyushin IL96-300", "I93"}, + {"Ilyushin IL114", "I14"}, + {"Lockheed L-182 / 282 / 382 (L-100) Hercules", "LOH"}, + {"Lockheed L-188 Electra", "LOE"}, + {"Lockheed L-1011 Tristar", "L10"}, + {"Lockheed L-1049 Super Constellation", "L49"}, + {"McDonnell Douglas MD11", "M11"}, + {"McDonnell Douglas MD80", "M80"}, + {"McDonnell Douglas MD81", "M81"}, + {"McDonnell Douglas MD82", "M82"}, + {"McDonnell Douglas MD83", "M83"}, + {"McDonnell Douglas MD87", "M87"}, + {"McDonnell Douglas MD88", "M88"}, + {"McDonnell Douglas MD90", "M90"}, + {"Sukhoi Superjet 100-95", "SU9"}, + {"Tupolev Tu-134", "TU3"}, + {"Tupolev Tu-154", "TU5"}, + {"Tupolev Tu-204", "T20"}, + {"Yakovlev Yak-40", "YK4"}, + {"Yakovlev Yak-42", "YK2"}, +}}; + +const std::array airports = {{ + {"Adelaide International Airport", "ADL"}, + {"Adolfo Suarez Madrid-Barajas Airport", "MAD"}, + {"Aeroparque Jorge Newbery Airport", "AEP"}, + {"Afonso Pena International Airport", "CWB"}, + {"Alfonso Bonilla Aragon International Airport", "CLO"}, + {"Amsterdam Airport Schiphol", "AMS"}, + {"Arturo Merino Benitez International Airport", "SCL"}, + {"Auckland International Airport", "AKL"}, + {"Beijing Capital International Airport", "PEK"}, + {"Belem Val de Cans International Airport", "BEL"}, + { + "Belo Horizonte Tancredo Neves International Airport", + "CNF", + }, + {"Berlin-Tegel Airport", "TXL"}, + {"Bole International Airport", "ADD"}, + { + "Brasilia-Presidente Juscelino Kubitschek International Airport", + "BSB", + }, + {"Brisbane International Airport", "BNE"}, + {"Brussels Airport", "BRU"}, + {"Cairns Airport", "CNS"}, + {"Cairo International Airport", "CAI"}, + {"Canberra Airport", "CBR"}, + {"Capetown International Airport", "CPT"}, + {"Charles de Gaulle International Airport", "CDG"}, + {"Charlotte Douglas International Airport", "CLT"}, + {"Chengdu Shuangliu International Airport", "CTU"}, + {"Chhatrapati Shivaji International Airport", "BOM"}, + {"Chicago O'Hare International Airport", "ORD"}, + {"Chongqing Jiangbei International Airport", "CKG"}, + {"Christchurch International Airport", "CHC"}, + {"Copenhagen Kastrup Airport", "CPH"}, + {"Dallas Fort Worth International Airport", "DFW"}, + {"Daniel K. Inouye International Airport", "HNL"}, + {"Denver International Airport", "DEN"}, + {"Don Mueang International Airport", "DMK"}, + {"Dubai International Airport", "DXB"}, + {"Dublin Airport", "DUB"}, + {"Dusseldorf Airport", "DUS"}, + {"El Dorado International Airport", "BOG"}, + {"Eleftherios Venizelos International Airport", "ATH"}, + {"Faa'a International Airport", "PPT"}, + {"Fort Lauderdale Hollywood International Airport", "FLL"}, + {"Fortaleza Pinto Martins International Airport", "FOR"}, + {"Frankfurt am Main Airport", "FRA"}, + {"George Bush Intercontinental Houston Airport", "IAH"}, + {"Gold Coast Airport", "OOL"}, + { + "Guarulhos - Governador Andre Franco Montoro International Airport", + "GRU", + }, + {"Hartsfield-Jackson Atlanta International Airport", "ATL"}, + {"Helsinki Vantaa Airport", "HEL"}, + {"Hobart International Airport", "HBA"}, + {"Hong Kong International Airport", "HKG"}, + {"Houari Boumediene Airport", "ALG"}, + {"Hurgada International Airport", "HRG"}, + {"Incheon International Airport", "ICN"}, + {"Indira Gandhi International Airport", "DEL"}, + {"Istanbul Airport", "IST"}, + {"Jacksons International Airport", "POM"}, + {"Jeju International Airport", "CJU"}, + {"John F Kennedy International Airport", "JFK"}, + {"Jorge Chavez International Airport", "LIM"}, + {"Jose Maria Cordova International Airport", "MDE"}, + {"Josep Tarradellas Barcelona-El Prat Airport", "BCN"}, + {"Kahului Airport", "OGG"}, + {"King Abdulaziz International Airport", "JED"}, + {"Kuala Lumpur International Airport", "KUL"}, + {"Kunming Changshui International Airport", "KMG"}, + {"La Tontouta International Airport", "NOU"}, + {"Leonardo da Vinci-Fiumicino Airport", "FCO"}, + {"London Heathrow Airport", "LHR"}, + {"Los Angeles International Airport", "LAX"}, + {"McCarran International Airport", "LAS"}, + {"Melbourne International Airport", "MEL"}, + {"Mexico City International Airport", "MEX"}, + {"Miami International Airport", "MIA"}, + {"Ministro Pistarini International Airport", "EZE"}, + { + "Minneapolis-St Paul International/Wold-Chamberlain Airport", + "MSP", + }, + {"Mohammed V International Airport", "CMN"}, + {"Moscow Domodedovo Airport", "DME"}, + {"Munich Airport", "MUC"}, + {"Murtala Muhammed International Airport", "LOS"}, + {"Nadi International Airport", "NAN"}, + {"Nairobi Jomo Kenyatta International Airport", "NBO"}, + {"Narita International Airport", "NRT"}, + {"Newark Liberty International Airport", "EWR"}, + {"Ninoy Aquino International Airport", "MNL"}, + {"Noumea Magenta Airport", "GEA"}, + {"O. R. Tambo International Airport", "JNB"}, + {"Orlando International Airport", "MCO"}, + {"Oslo Lufthavn", "OSL"}, + {"Perth Airport", "PER"}, + {"Phoenix Sky Harbor International Airport", "PHX"}, + { + "Recife Guararapes-Gilberto Freyre International Airport", + "REC", + }, + {"Rio de Janeiro Galeao International Airport", "GIG"}, + {"Salgado Filho International Airport", "POA"}, + { + "Salvador Deputado Luis Eduardo Magalhaes International Airport", + "SSA", + }, + {"San Francisco International Airport", "SFO"}, + {"Santos Dumont Airport", "SDU"}, + {"Sao Paulo-Congonhas Airport", "CGH"}, + {"Seattle Tacoma International Airport", "SEA"}, + {"Shanghai Hongqiao International Airport", "SHA"}, + {"Shanghai Pudong International Airport", "PVG"}, + {"Shenzhen Bao'an International Airport", "SZX"}, + {"Sheremetyevo International Airport", "SVO"}, + {"Singapore Changi Airport", "SIN"}, + {"Soekarno-Hatta International Airport", "CGK"}, + {"Stockholm-Arlanda Airport", "ARN"}, + {"Suvarnabhumi Airport", "BKK"}, + {"Sydney Kingsford Smith International Airport", "SYD"}, + {"Taiwan Taoyuan International Airport", "TPE"}, + {"Tan Son Nhat International Airport", "SGN"}, + {"Tokyo Haneda International Airport", "HND"}, + {"Toronto Pearson International Airport", "YYZ"}, + {"Tunis Carthage International Airport", "TUN"}, + {"Vancouver International Airport", "YVR"}, + {"Vienna International Airport", "VIE"}, + {"Viracopos International Airport", "VCP"}, + {"Vnukovo International Airport", "VKO"}, + {"Wellington International Airport", "WLG"}, + {"Xi'an Xianyang International Airport", "XIY"}, + {"Zhukovsky International Airport", "ZIA"}, + {"Zurich Airport", "ZRH"}, +}}; + +const std::unordered_map aircraftTypeMaxRows = { + {Airline::AircraftType::Regional, 20}, + {Airline::AircraftType::Narrowbody, 40}, + {Airline::AircraftType::Widebody, 60}, +}; + +const std::unordered_map aircraftTypeSeatLetters = { + {Airline::AircraftType::Regional, "ABCD"}, + {Airline::AircraftType::Narrowbody, "ABCDEF"}, + {Airline::AircraftType::Widebody, "ABCDEFGHJK"}, +}; + +} diff --git a/src/modules/airline/AirlineData.h b/src/modules/airline/AirlineData.h new file mode 100644 index 000000000..77090107d --- /dev/null +++ b/src/modules/airline/AirlineData.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include "faker-cxx/Airline.h" + +namespace faker +{ +extern const std::array aircraftTypes; +extern const std::array airlines; +extern const std::array airplanes; +extern const std::array airports; +extern const std::unordered_map aircraftTypeMaxRows; +extern const std::unordered_map aircraftTypeSeatLetters; +} diff --git a/src/modules/airline/data/AircraftTypes.h b/src/modules/airline/data/AircraftTypes.h deleted file mode 100644 index 322aad067..000000000 --- a/src/modules/airline/data/AircraftTypes.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector aircraftTypes = {"regional", "narrowbody", "widebody"}; -} diff --git a/src/modules/airline/data/Airlines.h b/src/modules/airline/data/Airlines.h deleted file mode 100644 index ffbe18cb7..000000000 --- a/src/modules/airline/data/Airlines.h +++ /dev/null @@ -1,137 +0,0 @@ -#pragma once - -#include -#include - -#include "faker-cxx/Airline.h" - -namespace faker -{ -const std::vector airlines{ - {.name = "Aegean Airlines", .iataCode = "A3"}, - {.name = "Aeroflot", .iataCode = "SU"}, - {.name = "Aerolineas Argentinas", .iataCode = "AR"}, - {.name = "Aeromexico", .iataCode = "AM"}, - {.name = "Air Algerie", .iataCode = "AH"}, - {.name = "Air Arabia", .iataCode = "G9"}, - {.name = "Air Canada", .iataCode = "AC"}, - {.name = "Air China", .iataCode = "CA"}, - {.name = "Air Europa", .iataCode = "UX"}, - {.name = "Air France-KLM", .iataCode = "AF"}, - {.name = "Air India", .iataCode = "AI"}, - {.name = "Air Mauritius", .iataCode = "MK"}, - {.name = "Air New Zealand", .iataCode = "NZ"}, - {.name = "Air Niugini", .iataCode = "PX"}, - {.name = "Air Tahiti", .iataCode = "VT"}, - {.name = "Air Tahiti Nui", .iataCode = "TN"}, - {.name = "Air Transat", .iataCode = "TS"}, - {.name = "AirAsia X", .iataCode = "D7"}, - {.name = "AirAsia", .iataCode = "AK"}, - {.name = "Aircalin", .iataCode = "SB"}, - {.name = "Alaska Airlines", .iataCode = "AS"}, - {.name = "Alitalia", .iataCode = "AZ"}, - {.name = "All Nippon Airways", .iataCode = "NH"}, - {.name = "Allegiant Air", .iataCode = "G4"}, - {.name = "American Airlines", .iataCode = "AA"}, - {.name = "Asiana Airlines", .iataCode = "OZ"}, - {.name = "Avianca", .iataCode = "AV"}, - {.name = "Azul Linhas Aereas Brasileiras", .iataCode = "AD"}, - {.name = "Azur Air", .iataCode = "ZF"}, - {.name = "Beijing Capital Airlines", .iataCode = "JD"}, - {.name = "Boliviana de Aviacion", .iataCode = "OB"}, - {.name = "British Airways", .iataCode = "BA"}, - {.name = "Cathay Pacific", .iataCode = "CX"}, - {.name = "Cebu Pacific Air", .iataCode = "5J"}, - {.name = "China Airlines", .iataCode = "CI"}, - {.name = "China Eastern Airlines", .iataCode = "MU"}, - {.name = "China Southern Airlines", .iataCode = "CZ"}, - {.name = "Condor", .iataCode = "DE"}, - {.name = "Copa Airlines", .iataCode = "CM"}, - {.name = "Delta Air Lines", .iataCode = "DL"}, - {.name = "Easyfly", .iataCode = "VE"}, - {.name = "EasyJet", .iataCode = "U2"}, - {.name = "EcoJet", .iataCode = "8J"}, - {.name = "Egyptair", .iataCode = "MS"}, - {.name = "El Al", .iataCode = "LY"}, - {.name = "Emirates Airlines", .iataCode = "EK"}, - {.name = "Ethiopian Airlines", .iataCode = "ET"}, - {.name = "Etihad Airways", .iataCode = "EY"}, - {.name = "EVA Air", .iataCode = "BR"}, - {.name = "Fiji Airways", .iataCode = "FJ"}, - {.name = "Finnair", .iataCode = "AY"}, - {.name = "Flybondi", .iataCode = "FO"}, - {.name = "Flydubai", .iataCode = "FZ"}, - {.name = "FlySafair", .iataCode = "FA"}, - {.name = "Frontier Airlines", .iataCode = "F9"}, - {.name = "Garuda Indonesia", .iataCode = "GA"}, - {.name = "Go First", .iataCode = "G8"}, - {.name = "Gol Linhas Aereas Inteligentes", .iataCode = "G3"}, - {.name = "Hainan Airlines", .iataCode = "HU"}, - {.name = "Hawaiian Airlines", .iataCode = "HA"}, - {.name = "IndiGo Airlines", .iataCode = "6E"}, - {.name = "Japan Airlines", .iataCode = "JL"}, - {.name = "Jeju Air", .iataCode = "7C"}, - {.name = "Jet2", .iataCode = "LS"}, - {.name = "JetBlue Airways", .iataCode = "B6"}, - {.name = "JetSMART", .iataCode = "JA"}, - {.name = "Juneyao Airlines", .iataCode = "HO"}, - {.name = "Kenya Airways", .iataCode = "KQ"}, - {.name = "Korean Air", .iataCode = "KE"}, - {.name = "Kulula.com", .iataCode = "MN"}, - {.name = "LATAM Airlines", .iataCode = "LA"}, - {.name = "Lion Air", .iataCode = "JT"}, - {.name = "LOT Polish Airlines", .iataCode = "LO"}, - {.name = "Lufthansa", .iataCode = "LH"}, - {.name = "Libyan Airlines", .iataCode = "LN"}, - {.name = "Linea Aerea Amaszonas", .iataCode = "Z8"}, - {.name = "Malaysia Airlines", .iataCode = "MH"}, - {.name = "Nordwind Airlines", .iataCode = "N4"}, - {.name = "Norwegian Air Shuttle", .iataCode = "DY"}, - {.name = "Oman Air", .iataCode = "WY"}, - {.name = "Pakistan International Airlines", .iataCode = "PK"}, - {.name = "Pegasus Airlines", .iataCode = "PC"}, - {.name = "Philippine Airlines", .iataCode = "PR"}, - {.name = "Qantas Group", .iataCode = "QF"}, - {.name = "Qatar Airways", .iataCode = "QR"}, - {.name = "Republic Airways", .iataCode = "YX"}, - {.name = "Royal Air Maroc", .iataCode = "AT"}, - {.name = "Ryanair", .iataCode = "FR"}, - {.name = "S7 Airlines", .iataCode = "S7"}, - {.name = "SAS", .iataCode = "SK"}, - {.name = "Satena", .iataCode = "9R"}, - {.name = "Saudia", .iataCode = "SV"}, - {.name = "Shandong Airlines", .iataCode = "SC"}, - {.name = "Sichuan Airlines", .iataCode = "3U"}, - {.name = "Singapore Airlines", .iataCode = "SQ"}, - {.name = "Sky Airline", .iataCode = "H2"}, - {.name = "SkyWest Airlines", .iataCode = "OO"}, - {.name = "South African Airways", .iataCode = "SA"}, - {.name = "Southwest Airlines", .iataCode = "WN"}, - {.name = "SpiceJet", .iataCode = "SG"}, - {.name = "Spirit Airlines", .iataCode = "NK"}, - {.name = "Spring Airlines", .iataCode = "9S"}, - {.name = "SriLankan Airlines", .iataCode = "UL"}, - {.name = "Star Peru", .iataCode = "2I"}, - {.name = "Sun Country Airlines", .iataCode = "SY"}, - {.name = "SunExpress", .iataCode = "XQ"}, - {.name = "TAP Air Portugal", .iataCode = "TP"}, - {.name = "Thai AirAsia", .iataCode = "FD"}, - {.name = "Thai Airways", .iataCode = "TG"}, - {.name = "TUI Airways", .iataCode = "BY"}, - {.name = "Tunisair", .iataCode = "TU"}, - {.name = "Turkish Airlines", .iataCode = "TK"}, - {.name = "Ukraine International", .iataCode = "PS"}, - {.name = "United Airlines", .iataCode = "UA"}, - {.name = "Ural Airlines", .iataCode = "U6"}, - {.name = "VietJet Air", .iataCode = "VJ"}, - {.name = "Vietnam Airlines", .iataCode = "VN"}, - {.name = "Virgin Atlantic Airways", .iataCode = "VS"}, - {.name = "Virgin Australia", .iataCode = "VA"}, - {.name = "VivaAerobus", .iataCode = "VB"}, - {.name = "VOEPASS Linhas Aereas", .iataCode = "2Z"}, - {.name = "Volaris", .iataCode = "Y4"}, - {.name = "WestJet", .iataCode = "WS"}, - {.name = "Wingo", .iataCode = "P5"}, - {.name = "Wizz Air", .iataCode = "W6"}, -}; -} diff --git a/src/modules/airline/data/Airplanes.h b/src/modules/airline/data/Airplanes.h deleted file mode 100644 index 4666c5695..000000000 --- a/src/modules/airline/data/Airplanes.h +++ /dev/null @@ -1,167 +0,0 @@ -#pragma once - -#include -#include - -#include "faker-cxx/Airline.h" - -namespace faker -{ -const std::vector airplanes{ - {.name = "Aerospatiale/BAC Concorde", .iataTypeCode = "SSC"}, - {.name = "Airbus A300", .iataTypeCode = "AB3"}, - {.name = "Airbus A310", .iataTypeCode = "310"}, - {.name = "Airbus A310-200", .iataTypeCode = "312"}, - {.name = "Airbus A310-300", .iataTypeCode = "313"}, - {.name = "Airbus A318", .iataTypeCode = "318"}, - {.name = "Airbus A319", .iataTypeCode = "319"}, - {.name = "Airbus A319neo", .iataTypeCode = "31N"}, - {.name = "Airbus A320", .iataTypeCode = "320"}, - {.name = "Airbus A320neo", .iataTypeCode = "32N"}, - {.name = "Airbus A321", .iataTypeCode = "321"}, - {.name = "Airbus A321neo", .iataTypeCode = "32Q"}, - {.name = "Airbus A330", .iataTypeCode = "330"}, - {.name = "Airbus A330-200", .iataTypeCode = "332"}, - {.name = "Airbus A330-300", .iataTypeCode = "333"}, - {.name = "Airbus A330-800neo", .iataTypeCode = "338"}, - {.name = "Airbus A330-900neo", .iataTypeCode = "339"}, - {.name = "Airbus A340", .iataTypeCode = "340"}, - {.name = "Airbus A340-200", .iataTypeCode = "342"}, - {.name = "Airbus A340-300", .iataTypeCode = "343"}, - {.name = "Airbus A340-500", .iataTypeCode = "345"}, - {.name = "Airbus A340-600", .iataTypeCode = "346"}, - {.name = "Airbus A350", .iataTypeCode = "350"}, - {.name = "Airbus A350-900", .iataTypeCode = "359"}, - {.name = "Airbus A350-1000", .iataTypeCode = "351"}, - {.name = "Airbus A380", .iataTypeCode = "380"}, - {.name = "Airbus A380-800", .iataTypeCode = "388"}, - {.name = "Antonov An-12", .iataTypeCode = "ANF"}, - {.name = "Antonov An-24", .iataTypeCode = "AN4"}, - {.name = "Antonov An-26", .iataTypeCode = "A26"}, - {.name = "Antonov An-28", .iataTypeCode = "A28"}, - {.name = "Antonov An-30", .iataTypeCode = "A30"}, - {.name = "Antonov An-32", .iataTypeCode = "A32"}, - {.name = "Antonov An-72", .iataTypeCode = "AN7"}, - {.name = "Antonov An-124 Ruslan", .iataTypeCode = "A4F"}, - {.name = "Antonov An-140", .iataTypeCode = "A40"}, - {.name = "Antonov An-148", .iataTypeCode = "A81"}, - {.name = "Antonov An-158", .iataTypeCode = "A58"}, - {.name = "Antonov An-225 Mriya", .iataTypeCode = "A5F"}, - {.name = "Boeing 707", .iataTypeCode = "703"}, - {.name = "Boeing 717", .iataTypeCode = "717"}, - {.name = "Boeing 720B", .iataTypeCode = "B72"}, - {.name = "Boeing 727", .iataTypeCode = "727"}, - {.name = "Boeing 727-100", .iataTypeCode = "721"}, - {.name = "Boeing 727-200", .iataTypeCode = "722"}, - {.name = "Boeing 737 MAX 7", .iataTypeCode = "7M7"}, - {.name = "Boeing 737 MAX 8", .iataTypeCode = "7M8"}, - {.name = "Boeing 737 MAX 9", .iataTypeCode = "7M9"}, - {.name = "Boeing 737 MAX 10", .iataTypeCode = "7MJ"}, - {.name = "Boeing 737", .iataTypeCode = "737"}, - {.name = "Boeing 737-100", .iataTypeCode = "731"}, - {.name = "Boeing 737-200", .iataTypeCode = "732"}, - {.name = "Boeing 737-300", .iataTypeCode = "733"}, - {.name = "Boeing 737-400", .iataTypeCode = "734"}, - {.name = "Boeing 737-500", .iataTypeCode = "735"}, - {.name = "Boeing 737-600", .iataTypeCode = "736"}, - {.name = "Boeing 737-700", .iataTypeCode = "73G"}, - {.name = "Boeing 737-800", .iataTypeCode = "738"}, - {.name = "Boeing 737-900", .iataTypeCode = "739"}, - {.name = "Boeing 747", .iataTypeCode = "747"}, - {.name = "Boeing 747-100", .iataTypeCode = "741"}, - {.name = "Boeing 747-200", .iataTypeCode = "742"}, - {.name = "Boeing 747-300", .iataTypeCode = "743"}, - {.name = "Boeing 747-400", .iataTypeCode = "744"}, - {.name = "Boeing 747-400D", .iataTypeCode = "74J"}, - {.name = "Boeing 747-8", .iataTypeCode = "748"}, - {.name = "Boeing 747SP", .iataTypeCode = "74L"}, - {.name = "Boeing 747SR", .iataTypeCode = "74R"}, - {.name = "Boeing 757", .iataTypeCode = "757"}, - {.name = "Boeing 757-200", .iataTypeCode = "752"}, - {.name = "Boeing 757-300", .iataTypeCode = "753"}, - {.name = "Boeing 767", .iataTypeCode = "767"}, - {.name = "Boeing 767-200", .iataTypeCode = "762"}, - {.name = "Boeing 767-300", .iataTypeCode = "763"}, - {.name = "Boeing 767-400", .iataTypeCode = "764"}, - {.name = "Boeing 777", .iataTypeCode = "777"}, - {.name = "Boeing 777-200", .iataTypeCode = "772"}, - {.name = "Boeing 777-200LR", .iataTypeCode = "77L"}, - {.name = "Boeing 777-300", .iataTypeCode = "773"}, - {.name = "Boeing 777-300ER", .iataTypeCode = "77W"}, - {.name = "Boeing 787", .iataTypeCode = "787"}, - {.name = "Boeing 787-8", .iataTypeCode = "788"}, - {.name = "Boeing 787-9", .iataTypeCode = "789"}, - {.name = "Boeing 787-10", .iataTypeCode = "781"}, - {.name = "Canadair Challenger", .iataTypeCode = "CCJ"}, - {.name = "Canadair CL-44", .iataTypeCode = "CL4"}, - {.name = "Canadair Regional Jet 100", .iataTypeCode = "CR1"}, - {.name = "Canadair Regional Jet 200", .iataTypeCode = "CR2"}, - {.name = "Canadair Regional Jet 700", .iataTypeCode = "CR7"}, - {.name = "Canadair Regional Jet 705", .iataTypeCode = "CRA"}, - {.name = "Canadair Regional Jet 900", .iataTypeCode = "CR9"}, - {.name = "Canadair Regional Jet 1000", .iataTypeCode = "CRK"}, - {.name = "De Havilland Canada DHC-2 Beaver", .iataTypeCode = "DHP"}, - {.name = "De Havilland Canada DHC-2 Turbo-Beaver", .iataTypeCode = "DHR"}, - {.name = "De Havilland Canada DHC-3 Otter", .iataTypeCode = "DHL"}, - {.name = "De Havilland Canada DHC-4 Caribou", .iataTypeCode = "DHC"}, - {.name = "De Havilland Canada DHC-6 Twin Otter", .iataTypeCode = "DHT"}, - {.name = "De Havilland Canada DHC-7 Dash 7", .iataTypeCode = "DH7"}, - {.name = "De Havilland Canada DHC-8-100 Dash 8 / 8Q", .iataTypeCode = "DH1"}, - {.name = "De Havilland Canada DHC-8-200 Dash 8 / 8Q", .iataTypeCode = "DH2"}, - {.name = "De Havilland Canada DHC-8-300 Dash 8 / 8Q", .iataTypeCode = "DH3"}, - {.name = "De Havilland Canada DHC-8-400 Dash 8Q", .iataTypeCode = "DH4"}, - {.name = "De Havilland DH.104 Dove", .iataTypeCode = "DHD"}, - {.name = "De Havilland DH.114 Heron", .iataTypeCode = "DHH"}, - {.name = "Douglas DC-3", .iataTypeCode = "D3F"}, - {.name = "Douglas DC-6", .iataTypeCode = "D6F"}, - {.name = "Douglas DC-8-50", .iataTypeCode = "D8T"}, - {.name = "Douglas DC-8-62", .iataTypeCode = "D8L"}, - {.name = "Douglas DC-8-72", .iataTypeCode = "D8Q"}, - {.name = "Douglas DC-9-10", .iataTypeCode = "D91"}, - {.name = "Douglas DC-9-20", .iataTypeCode = "D92"}, - {.name = "Douglas DC-9-30", .iataTypeCode = "D93"}, - {.name = "Douglas DC-9-40", .iataTypeCode = "D94"}, - {.name = "Douglas DC-9-50", .iataTypeCode = "D95"}, - {.name = "Douglas DC-10", .iataTypeCode = "D10"}, - {.name = "Douglas DC-10-10", .iataTypeCode = "D1X"}, - {.name = "Douglas DC-10-30", .iataTypeCode = "D1Y"}, - {.name = "Embraer 170", .iataTypeCode = "E70"}, - {.name = "Embraer 175", .iataTypeCode = "E75"}, - {.name = "Embraer 190", .iataTypeCode = "E90"}, - {.name = "Embraer 195", .iataTypeCode = "E95"}, - {.name = "Embraer E190-E2", .iataTypeCode = "290"}, - {.name = "Embraer E195-E2", .iataTypeCode = "295"}, - {.name = "Embraer EMB.110 Bandeirante", .iataTypeCode = "EMB"}, - {.name = "Embraer EMB.120 Brasilia", .iataTypeCode = "EM2"}, - {.name = "Embraer Legacy 600", .iataTypeCode = "ER3"}, - {.name = "Embraer Phenom 100", .iataTypeCode = "EP1"}, - {.name = "Embraer Phenom 300", .iataTypeCode = "EP3"}, - {.name = "Embraer RJ135", .iataTypeCode = "ER3"}, - {.name = "Embraer RJ140", .iataTypeCode = "ERD"}, - {.name = "Embraer RJ145 Amazon", .iataTypeCode = "ER4"}, - {.name = "Ilyushin IL18", .iataTypeCode = "IL8"}, - {.name = "Ilyushin IL62", .iataTypeCode = "IL6"}, - {.name = "Ilyushin IL76", .iataTypeCode = "IL7"}, - {.name = "Ilyushin IL86", .iataTypeCode = "ILW"}, - {.name = "Ilyushin IL96-300", .iataTypeCode = "I93"}, - {.name = "Ilyushin IL114", .iataTypeCode = "I14"}, - {.name = "Lockheed L-182 / 282 / 382 (L-100) Hercules", .iataTypeCode = "LOH"}, - {.name = "Lockheed L-188 Electra", .iataTypeCode = "LOE"}, - {.name = "Lockheed L-1011 Tristar", .iataTypeCode = "L10"}, - {.name = "Lockheed L-1049 Super Constellation", .iataTypeCode = "L49"}, - {.name = "McDonnell Douglas MD11", .iataTypeCode = "M11"}, - {.name = "McDonnell Douglas MD80", .iataTypeCode = "M80"}, - {.name = "McDonnell Douglas MD81", .iataTypeCode = "M81"}, - {.name = "McDonnell Douglas MD82", .iataTypeCode = "M82"}, - {.name = "McDonnell Douglas MD83", .iataTypeCode = "M83"}, - {.name = "McDonnell Douglas MD87", .iataTypeCode = "M87"}, - {.name = "McDonnell Douglas MD88", .iataTypeCode = "M88"}, - {.name = "McDonnell Douglas MD90", .iataTypeCode = "M90"}, - {.name = "Sukhoi Superjet 100-95", .iataTypeCode = "SU9"}, - {.name = "Tupolev Tu-134", .iataTypeCode = "TU3"}, - {.name = "Tupolev Tu-154", .iataTypeCode = "TU5"}, - {.name = "Tupolev Tu-204", .iataTypeCode = "T20"}, - {.name = "Yakovlev Yak-40", .iataTypeCode = "YK4"}, - {.name = "Yakovlev Yak-42", .iataTypeCode = "YK2"}, -}; -} diff --git a/src/modules/airline/data/Airports.h b/src/modules/airline/data/Airports.h deleted file mode 100644 index 5b1455be0..000000000 --- a/src/modules/airline/data/Airports.h +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once - -#include -#include - -#include "faker-cxx/Airline.h" - -namespace faker -{ -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"}, - {.name = "Afonso Pena International Airport", .iataCode = "CWB"}, - {.name = "Alfonso Bonilla Aragon International Airport", .iataCode = "CLO"}, - {.name = "Amsterdam Airport Schiphol", .iataCode = "AMS"}, - {.name = "Arturo Merino Benitez International Airport", .iataCode = "SCL"}, - {.name = "Auckland International Airport", .iataCode = "AKL"}, - {.name = "Beijing Capital International Airport", .iataCode = "PEK"}, - {.name = "Belem Val de Cans International Airport", .iataCode = "BEL"}, - { - .name = "Belo Horizonte Tancredo Neves International Airport", - .iataCode = "CNF", - }, - {.name = "Berlin-Tegel Airport", .iataCode = "TXL"}, - {.name = "Bole International Airport", .iataCode = "ADD"}, - { - .name = "Brasilia-Presidente Juscelino Kubitschek International Airport", - .iataCode = "BSB", - }, - {.name = "Brisbane International Airport", .iataCode = "BNE"}, - {.name = "Brussels Airport", .iataCode = "BRU"}, - {.name = "Cairns Airport", .iataCode = "CNS"}, - {.name = "Cairo International Airport", .iataCode = "CAI"}, - {.name = "Canberra Airport", .iataCode = "CBR"}, - {.name = "Capetown International Airport", .iataCode = "CPT"}, - {.name = "Charles de Gaulle International Airport", .iataCode = "CDG"}, - {.name = "Charlotte Douglas International Airport", .iataCode = "CLT"}, - {.name = "Chengdu Shuangliu International Airport", .iataCode = "CTU"}, - {.name = "Chhatrapati Shivaji International Airport", .iataCode = "BOM"}, - {.name = "Chicago O'Hare International Airport", .iataCode = "ORD"}, - {.name = "Chongqing Jiangbei International Airport", .iataCode = "CKG"}, - {.name = "Christchurch International Airport", .iataCode = "CHC"}, - {.name = "Copenhagen Kastrup Airport", .iataCode = "CPH"}, - {.name = "Dallas Fort Worth International Airport", .iataCode = "DFW"}, - {.name = "Daniel K. Inouye International Airport", .iataCode = "HNL"}, - {.name = "Denver International Airport", .iataCode = "DEN"}, - {.name = "Don Mueang International Airport", .iataCode = "DMK"}, - {.name = "Dubai International Airport", .iataCode = "DXB"}, - {.name = "Dublin Airport", .iataCode = "DUB"}, - {.name = "Dusseldorf Airport", .iataCode = "DUS"}, - {.name = "El Dorado International Airport", .iataCode = "BOG"}, - {.name = "Eleftherios Venizelos International Airport", .iataCode = "ATH"}, - {.name = "Faa'a International Airport", .iataCode = "PPT"}, - {.name = "Fort Lauderdale Hollywood International Airport", .iataCode = "FLL"}, - {.name = "Fortaleza Pinto Martins International Airport", .iataCode = "FOR"}, - {.name = "Frankfurt am Main Airport", .iataCode = "FRA"}, - {.name = "George Bush Intercontinental Houston Airport", .iataCode = "IAH"}, - {.name = "Gold Coast Airport", .iataCode = "OOL"}, - { - .name = "Guarulhos - Governador Andre Franco Montoro International Airport", - .iataCode = "GRU", - }, - {.name = "Hartsfield-Jackson Atlanta International Airport", .iataCode = "ATL"}, - {.name = "Helsinki Vantaa Airport", .iataCode = "HEL"}, - {.name = "Hobart International Airport", .iataCode = "HBA"}, - {.name = "Hong Kong International Airport", .iataCode = "HKG"}, - {.name = "Houari Boumediene Airport", .iataCode = "ALG"}, - {.name = "Hurgada International Airport", .iataCode = "HRG"}, - {.name = "Incheon International Airport", .iataCode = "ICN"}, - {.name = "Indira Gandhi International Airport", .iataCode = "DEL"}, - {.name = "Istanbul Airport", .iataCode = "IST"}, - {.name = "Jacksons International Airport", .iataCode = "POM"}, - {.name = "Jeju International Airport", .iataCode = "CJU"}, - {.name = "John F Kennedy International Airport", .iataCode = "JFK"}, - {.name = "Jorge Chavez International Airport", .iataCode = "LIM"}, - {.name = "Jose Maria Cordova International Airport", .iataCode = "MDE"}, - {.name = "Josep Tarradellas Barcelona-El Prat Airport", .iataCode = "BCN"}, - {.name = "Kahului Airport", .iataCode = "OGG"}, - {.name = "King Abdulaziz International Airport", .iataCode = "JED"}, - {.name = "Kuala Lumpur International Airport", .iataCode = "KUL"}, - {.name = "Kunming Changshui International Airport", .iataCode = "KMG"}, - {.name = "La Tontouta International Airport", .iataCode = "NOU"}, - {.name = "Leonardo da Vinci-Fiumicino Airport", .iataCode = "FCO"}, - {.name = "London Heathrow Airport", .iataCode = "LHR"}, - {.name = "Los Angeles International Airport", .iataCode = "LAX"}, - {.name = "McCarran International Airport", .iataCode = "LAS"}, - {.name = "Melbourne International Airport", .iataCode = "MEL"}, - {.name = "Mexico City International Airport", .iataCode = "MEX"}, - {.name = "Miami International Airport", .iataCode = "MIA"}, - {.name = "Ministro Pistarini International Airport", .iataCode = "EZE"}, - { - .name = "Minneapolis-St Paul International/Wold-Chamberlain Airport", - .iataCode = "MSP", - }, - {.name = "Mohammed V International Airport", .iataCode = "CMN"}, - {.name = "Moscow Domodedovo Airport", .iataCode = "DME"}, - {.name = "Munich Airport", .iataCode = "MUC"}, - {.name = "Murtala Muhammed International Airport", .iataCode = "LOS"}, - {.name = "Nadi International Airport", .iataCode = "NAN"}, - {.name = "Nairobi Jomo Kenyatta International Airport", .iataCode = "NBO"}, - {.name = "Narita International Airport", .iataCode = "NRT"}, - {.name = "Newark Liberty International Airport", .iataCode = "EWR"}, - {.name = "Ninoy Aquino International Airport", .iataCode = "MNL"}, - {.name = "Noumea Magenta Airport", .iataCode = "GEA"}, - {.name = "O. R. Tambo International Airport", .iataCode = "JNB"}, - {.name = "Orlando International Airport", .iataCode = "MCO"}, - {.name = "Oslo Lufthavn", .iataCode = "OSL"}, - {.name = "Perth Airport", .iataCode = "PER"}, - {.name = "Phoenix Sky Harbor International Airport", .iataCode = "PHX"}, - { - .name = "Recife Guararapes-Gilberto Freyre International Airport", - .iataCode = "REC", - }, - {.name = "Rio de Janeiro Galeao International Airport", .iataCode = "GIG"}, - {.name = "Salgado Filho International Airport", .iataCode = "POA"}, - { - .name = "Salvador Deputado Luis Eduardo Magalhaes International Airport", - .iataCode = "SSA", - }, - {.name = "San Francisco International Airport", .iataCode = "SFO"}, - {.name = "Santos Dumont Airport", .iataCode = "SDU"}, - {.name = "Sao Paulo-Congonhas Airport", .iataCode = "CGH"}, - {.name = "Seattle Tacoma International Airport", .iataCode = "SEA"}, - {.name = "Shanghai Hongqiao International Airport", .iataCode = "SHA"}, - {.name = "Shanghai Pudong International Airport", .iataCode = "PVG"}, - {.name = "Shenzhen Bao'an International Airport", .iataCode = "SZX"}, - {.name = "Sheremetyevo International Airport", .iataCode = "SVO"}, - {.name = "Singapore Changi Airport", .iataCode = "SIN"}, - {.name = "Soekarno-Hatta International Airport", .iataCode = "CGK"}, - {.name = "Stockholm-Arlanda Airport", .iataCode = "ARN"}, - {.name = "Suvarnabhumi Airport", .iataCode = "BKK"}, - {.name = "Sydney Kingsford Smith International Airport", .iataCode = "SYD"}, - {.name = "Taiwan Taoyuan International Airport", .iataCode = "TPE"}, - {.name = "Tan Son Nhat International Airport", .iataCode = "SGN"}, - {.name = "Tokyo Haneda International Airport", .iataCode = "HND"}, - {.name = "Toronto Pearson International Airport", .iataCode = "YYZ"}, - {.name = "Tunis Carthage International Airport", .iataCode = "TUN"}, - {.name = "Vancouver International Airport", .iataCode = "YVR"}, - {.name = "Vienna International Airport", .iataCode = "VIE"}, - {.name = "Viracopos International Airport", .iataCode = "VCP"}, - {.name = "Vnukovo International Airport", .iataCode = "VKO"}, - {.name = "Wellington International Airport", .iataCode = "WLG"}, - {.name = "Xi'an Xianyang International Airport", .iataCode = "XIY"}, - {.name = "Zhukovsky International Airport", .iataCode = "ZIA"}, - {.name = "Zurich Airport", .iataCode = "ZRH"}, -}; -} diff --git a/src/modules/airline/data/Seat.h b/src/modules/airline/data/Seat.h deleted file mode 100644 index c37527b76..000000000 --- a/src/modules/airline/data/Seat.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "faker-cxx/Airline.h" - -namespace faker -{ -const std::map aircraftTypeMaxRows = { - {Airline::AircraftType::Regional, 20}, - {Airline::AircraftType::Narrowbody, 40}, - {Airline::AircraftType::Widebody, 60}, -}; - -const std::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'}}, -}; -} diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 367e1e774..1d3927ae3 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -1,7 +1,7 @@ #include "faker-cxx/Finance.h" #include "../../common/FormatHelper.h" -#include "../../common/mappers/precisionMapper/PrecisionMapper.h" +#include "../../common/PrecisionMapper.h" #include "data/AccountTypes.h" #include "data/BankIndentifiersCodes.h" #include "data/CreditCardsFormats.h" diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index d29b49aec..05e56fbf2 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -4,11 +4,11 @@ #include #include "../../common/FormatHelper.h" -#include "../../common/mappers/precisionMapper/PrecisionMapper.h" +#include "../../common/PrecisionMapper.h" #include "data/argentina/ArgentinaAddresses.h" #include "data/australia/AustraliaAddresses.h" -#include "data/brazil/BrazilAddresses.h" #include "data/belgium/BelgiumAddresses.h" +#include "data/brazil/BrazilAddresses.h" #include "data/Countries.h" #include "data/czech/CzechAddresses.h" #include "data/denmark/DenmarkAddresses.h" @@ -37,50 +37,30 @@ namespace faker namespace { const std::map countryToCountryAddressesMapping{ - {AddressCountry::Argentina, argentinaAddresses}, - {AddressCountry::Usa, usaAddresses}, - {AddressCountry::Poland, polandAddresses}, - {AddressCountry::Russia, russiaAddresses}, - {AddressCountry::France, franceAddresses}, - {AddressCountry::Ukraine, ukraineAddresses}, - {AddressCountry::Italy, italyAddresses}, - {AddressCountry::Germany, germanyAddresses}, - {AddressCountry::Czech, czechAddresses}, - {AddressCountry::Australia, australiaAddresses}, - {AddressCountry::India, indiaAddresses}, - {AddressCountry::Denmark, denmarkAddresses}, - {AddressCountry::Spain, spainAddresses}, - {AddressCountry::Brazil, brazilAddresses}, - {AddressCountry::Finland, finlandAddresses}, - {AddressCountry::Estonia, estoniaAddresses}, - {AddressCountry::Romania, romaniaAddresses}, - {AddressCountry::Latvia, latviaAddresses}, - {AddressCountry::Nepal, nepalAddresses}, - {AddressCountry::Belgium, belgiumAddresses}, + {AddressCountry::Argentina, argentinaAddresses}, {AddressCountry::Usa, usaAddresses}, + {AddressCountry::Poland, polandAddresses}, {AddressCountry::Russia, russiaAddresses}, + {AddressCountry::France, franceAddresses}, {AddressCountry::Ukraine, ukraineAddresses}, + {AddressCountry::Italy, italyAddresses}, {AddressCountry::Germany, germanyAddresses}, + {AddressCountry::Czech, czechAddresses}, {AddressCountry::Australia, australiaAddresses}, + {AddressCountry::India, indiaAddresses}, {AddressCountry::Denmark, denmarkAddresses}, + {AddressCountry::Spain, spainAddresses}, {AddressCountry::Brazil, brazilAddresses}, + {AddressCountry::Finland, finlandAddresses}, {AddressCountry::Estonia, estoniaAddresses}, + {AddressCountry::Romania, romaniaAddresses}, {AddressCountry::Latvia, latviaAddresses}, + {AddressCountry::Nepal, nepalAddresses}, {AddressCountry::Belgium, belgiumAddresses}, {AddressCountry::Serbia, serbiaAddresses}, }; const std::map countryAddressToCountryMapping{ - {AddressCountry::Argentina, Country::Argentina}, - {AddressCountry::Usa, Country::Usa}, - {AddressCountry::Poland, Country::Poland}, - {AddressCountry::Russia, Country::Russia}, - {AddressCountry::France, Country::France}, - {AddressCountry::Ukraine, Country::Ukraine}, - {AddressCountry::Italy, Country::Italy}, - {AddressCountry::Germany, Country::Germany}, - {AddressCountry::Czech, Country::Czech}, - {AddressCountry::Australia, Country::Australia}, - {AddressCountry::India, Country::India}, - {AddressCountry::Denmark, Country::Denmark}, - {AddressCountry::Spain, Country::Spain}, - {AddressCountry::Brazil, Country::Brazil}, - {AddressCountry::Finland, Country::Finland}, - {AddressCountry::Estonia, Country::Estonia}, - {AddressCountry::Romania, Country::Romania}, - {AddressCountry::Latvia, Country::Latvia}, - {AddressCountry::Nepal, Country::Nepal}, - {AddressCountry::Belgium, Country::Belgium}, + {AddressCountry::Argentina, Country::Argentina}, {AddressCountry::Usa, Country::Usa}, + {AddressCountry::Poland, Country::Poland}, {AddressCountry::Russia, Country::Russia}, + {AddressCountry::France, Country::France}, {AddressCountry::Ukraine, Country::Ukraine}, + {AddressCountry::Italy, Country::Italy}, {AddressCountry::Germany, Country::Germany}, + {AddressCountry::Czech, Country::Czech}, {AddressCountry::Australia, Country::Australia}, + {AddressCountry::India, Country::India}, {AddressCountry::Denmark, Country::Denmark}, + {AddressCountry::Spain, Country::Spain}, {AddressCountry::Brazil, Country::Brazil}, + {AddressCountry::Finland, Country::Finland}, {AddressCountry::Estonia, Country::Estonia}, + {AddressCountry::Romania, Country::Romania}, {AddressCountry::Latvia, Country::Latvia}, + {AddressCountry::Nepal, Country::Nepal}, {AddressCountry::Belgium, Country::Belgium}, {AddressCountry::Serbia, Country::Serbia}, }; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9589ad4be..bdd27b1f8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,7 +13,7 @@ add_code_coverage_all_targets() set(FAKER_UT_SOURCES common/FormatHelperTest.cpp common/LuhnCheckTest.cpp - common/mappers/precisionMapper/PrecisionMapperTest.cpp + common/PrecisionMapperTest.cpp common/StringHelperTest.cpp modules/airline/AirlineTest.cpp modules/animal/AnimalTest.cpp diff --git a/tests/common/FormatHelperTest.cpp b/tests/common/FormatHelperTest.cpp index ae331fd2e..646f11606 100644 --- a/tests/common/FormatHelperTest.cpp +++ b/tests/common/FormatHelperTest.cpp @@ -2,8 +2,6 @@ #include "gtest/gtest.h" -#include "common/errors/TokenGeneratorNotFoundError.h" - using namespace ::testing; using namespace faker; @@ -36,7 +34,7 @@ TEST_F(FormatHelperTest, givenTokensWithNotDefinedGenerator_shouldThrow) const auto dataGeneratorsMapping = std::map>{ {"hello", []() { return "library"; }}, {"faker", []() { return "cxx"; }}, {"cxx", []() { return "faker"; }}}; - ASSERT_THROW(FormatHelper::fillTokenValues(format, dataGeneratorsMapping), errors::TokenGeneratorNotFoundError); + ASSERT_THROW(FormatHelper::fillTokenValues(format, dataGeneratorsMapping), std::runtime_error); } TEST_F(FormatHelperTest, shouldFormat) diff --git a/tests/common/mappers/precisionMapper/PrecisionMapperTest.cpp b/tests/common/PrecisionMapperTest.cpp similarity index 94% rename from tests/common/mappers/precisionMapper/PrecisionMapperTest.cpp rename to tests/common/PrecisionMapperTest.cpp index 00d44a820..1100379f2 100644 --- a/tests/common/mappers/precisionMapper/PrecisionMapperTest.cpp +++ b/tests/common/PrecisionMapperTest.cpp @@ -1,4 +1,4 @@ -#include "common/mappers/precisionMapper/PrecisionMapper.h" +#include "common/PrecisionMapper.h" #include "gtest/gtest.h" diff --git a/tests/modules/airline/AirlineTest.cpp b/tests/modules/airline/AirlineTest.cpp index 3ed764abf..32c7586d9 100644 --- a/tests/modules/airline/AirlineTest.cpp +++ b/tests/modules/airline/AirlineTest.cpp @@ -1,20 +1,14 @@ #include "faker-cxx/Airline.h" #include -#include #include "gtest/gtest.h" -#include "airline/data/AircraftTypes.h" -#include "airline/data/Airlines.h" -#include "airline/data/Airplanes.h" -#include "airline/data/Airports.h" -#include "airline/data/Seat.h" +#include "airline/AirlineData.h" using namespace ::testing; using namespace faker; -// TODO: add flight number tests class AirlineTest : public Test { public: @@ -22,15 +16,15 @@ class AirlineTest : public Test TEST_F(AirlineTest, shouldGenerateAircraftType) { - std::string generatedAircraftType = Airline::aircraftType(); + const auto generatedAircraftType = Airline::aircraftType(); - ASSERT_TRUE(std::ranges::any_of(aircraftTypes, [generatedAircraftType](const std::string& aircraftType) + ASSERT_TRUE(std::ranges::any_of(aircraftTypes, [generatedAircraftType](const std::string_view& aircraftType) { return aircraftType == generatedAircraftType; })); } TEST_F(AirlineTest, shouldGenerateAirline) { - Airline::AirlineInfo generatedAirline = Airline::airline(); + const auto generatedAirline = Airline::airline(); ASSERT_TRUE(std::ranges::any_of( airlines, [generatedAirline](const Airline::AirlineInfo& airline) @@ -39,7 +33,7 @@ TEST_F(AirlineTest, shouldGenerateAirline) TEST_F(AirlineTest, shouldGenerateAirplane) { - Airline::Airplane generatedAirplane = Airline::airplane(); + const auto generatedAirplane = Airline::airplane(); ASSERT_TRUE(std::ranges::any_of(airplanes, [generatedAirplane](const Airline::Airplane& airplane) { @@ -50,7 +44,7 @@ TEST_F(AirlineTest, shouldGenerateAirplane) TEST_F(AirlineTest, shouldGenerateAirport) { - Airline::Airport generatedAirport = Airline::airport(); + const auto generatedAirport = Airline::airport(); ASSERT_TRUE(std::ranges::any_of( airports, [generatedAirport](const Airline::Airport& airport) @@ -59,12 +53,12 @@ TEST_F(AirlineTest, shouldGenerateAirport) TEST_F(AirlineTest, shouldGenerateRecordLocator) { - std::string generatedRecordLocatorWithAlpha = Airline::recordLocator(false); + const auto generatedRecordLocatorWithAlpha = Airline::recordLocator(false); ASSERT_EQ(generatedRecordLocatorWithAlpha.length(), 6); ASSERT_TRUE(std::ranges::all_of(generatedRecordLocatorWithAlpha, [](const char& c) { return std::isalpha(c); })); - std::string generatedRecordLocatorWithNumerics = Airline::recordLocator(true); + const auto generatedRecordLocatorWithNumerics = Airline::recordLocator(true); ASSERT_EQ(generatedRecordLocatorWithNumerics.length(), 6); ASSERT_TRUE(std::ranges::all_of(generatedRecordLocatorWithNumerics, [](const char& c) { return std::isalnum(c); })); @@ -72,7 +66,7 @@ TEST_F(AirlineTest, shouldGenerateRecordLocator) TEST_F(AirlineTest, shouldGenerateSeatNumberRegional) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Regional); + const auto generatedSeatNumber = Airline::seat(Airline::AircraftType::Regional); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); @@ -80,6 +74,7 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberRegional) int max = aircraftTypeMaxRows.at(Airline::AircraftType::Regional); bool inRange = false; + for (int i = max; i >= min; --i) { std::string numberStr = std::to_string(i); @@ -98,7 +93,7 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberRegional) TEST_F(AirlineTest, shouldGenerateSeatNumberNarrowbody) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Narrowbody); + const auto generatedSeatNumber = Airline::seat(Airline::AircraftType::Narrowbody); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); @@ -106,12 +101,15 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberNarrowbody) int max = aircraftTypeMaxRows.at(Airline::AircraftType::Narrowbody); bool inRange = false; + for (int i = max; i >= min; --i) { - std::string numberStr = std::to_string(i); + const auto numberStr = std::to_string(i); + if (generatedSeatNumber.find(numberStr) != std::string::npos) { inRange = true; + break; } } @@ -124,7 +122,7 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberNarrowbody) TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) { - std::string generatedSeatNumber = Airline::seat(Airline::AircraftType::Widebody); + const auto generatedSeatNumber = Airline::seat(Airline::AircraftType::Widebody); ASSERT_TRUE(generatedSeatNumber.length() == 2 || generatedSeatNumber.length() == 3); @@ -132,12 +130,15 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) int max = aircraftTypeMaxRows.at(Airline::AircraftType::Widebody); bool inRange = false; + for (int i = max; i >= min; --i) { - std::string numberStr = std::to_string(i); + const auto numberStr = std::to_string(i); + if (generatedSeatNumber.find(numberStr) != std::string::npos) { inRange = true; + break; } } @@ -150,8 +151,8 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) TEST_F(AirlineTest, shouldGenerateFlightNumberNoLeadingZeros) { - std::string flightNumber = Airline::flightNumber(); - int flightNumberInt = std::stoi(flightNumber); + const auto flightNumber = Airline::flightNumber(); + const auto flightNumberInt = std::stoi(flightNumber); ASSERT_TRUE(flightNumber.length() == 4); @@ -163,7 +164,8 @@ TEST_F(AirlineTest, shouldGenerateFlightNumberLeadingZeros) bool leadingZero = false; while (!leadingZero) { - std::string flightNumber = Airline::flightNumber(true, 4); + const auto flightNumber = Airline::flightNumber(true, 4); + if (flightNumber.substr(0, 1) == "0") { leadingZero = true; @@ -175,6 +177,7 @@ TEST_F(AirlineTest, shouldGenerateFlightNumberLeadingZeros) TEST_F(AirlineTest, shouldGenerateFlightNumberByRange) { - std::string flightNumber = Airline::flightNumberByRange(false, {1, 6}); + const auto flightNumber = Airline::flightNumberByRange(false, {1, 6}); + ASSERT_TRUE(flightNumber.length() <= 6); }