diff --git a/include/faker-cxx/Airline.h b/include/faker-cxx/Airline.h index 6f424003..cd9c2c81 100644 --- a/include/faker-cxx/Airline.h +++ b/include/faker-cxx/Airline.h @@ -2,6 +2,7 @@ #include #include + #include "./types/AirlineTypes.h" namespace faker @@ -110,6 +111,6 @@ class Airline * Airline::flightNumber(false, {1, 4}) // "234" // "12" // "1234" * @endcode */ - static std::string flightNumber(bool addLeadingZeros = false, Range length = {1, 4}); + static std::string flightNumberByRange(bool addLeadingZeros = false, Range length = {1, 4}); }; } diff --git a/src/modules/airline/Airline.cpp b/src/modules/airline/Airline.cpp index 3316aae3..03648322 100644 --- a/src/modules/airline/Airline.cpp +++ b/src/modules/airline/Airline.cpp @@ -59,7 +59,7 @@ std::string Airline::flightNumber(bool addLeadingZeros, unsigned int length) return String::numeric(length, false); } -std::string Airline::flightNumber(bool addLeadingZeros, faker::Range length) +std::string Airline::flightNumberByRange(bool addLeadingZeros, faker::Range length) { if (addLeadingZeros) { @@ -69,3 +69,4 @@ std::string Airline::flightNumber(bool addLeadingZeros, faker::Range length) return String::numeric(Number::integer(length.min, length.max), false); } } + diff --git a/src/modules/airline/AirlineTest.cpp b/src/modules/airline/AirlineTest.cpp index 8ec32d08..cb31a939 100644 --- a/src/modules/airline/AirlineTest.cpp +++ b/src/modules/airline/AirlineTest.cpp @@ -1,6 +1,7 @@ #include "faker-cxx/Airline.h" #include +#include #include #include "gtest/gtest.h" @@ -10,6 +11,8 @@ #include "data/Airplanes.h" #include "data/Airports.h" #include "data/Seat.h" +#include "faker-cxx/Number.h" +#include "faker-cxx/String.h" using namespace ::testing; using namespace faker; @@ -147,3 +150,35 @@ TEST_F(AirlineTest, shouldGenerateSeatNumberWidebody) [generatedSeatNumber](char letter) { return generatedSeatNumber.back() == letter; })); } + +TEST_F(AirlineTest, shouldGenerateFlightNumberNoLeadingZeros) +{ + std::string flightNumber = Airline::flightNumber(); + int flightNumberInt = std::stoi(flightNumber); + + ASSERT_TRUE(flightNumber.length() == 4); + + ASSERT_TRUE((flightNumberInt > 999) && (flightNumberInt <= 9999)); +} + +TEST_F(AirlineTest, shouldGenerateFlightNumberLeadingZeros) +{ + bool leadingZero = false; + while (!leadingZero) + { + std::string flightNumber = Airline::flightNumber(true, 4); + if (flightNumber.substr(0, 1) == "0") + { + leadingZero = true; + } + } + + ASSERT_TRUE(leadingZero); +} + +TEST_F(AirlineTest, shouldGenerateFlightNumberByRange) +{ + std::string flightNumber = Airline::flightNumberByRange(false, {1, 6}); + ASSERT_TRUE(flightNumber.length() <= 6); +} +