Skip to content

Commit

Permalink
Merge branch 'main' into 163-feature/addBarcodeFunctionalitiesToComme…
Browse files Browse the repository at this point in the history
…rceModule
  • Loading branch information
sebastianbacik committed Nov 7, 2023
2 parents f340697 + 2b93e95 commit ef3e8b0
Show file tree
Hide file tree
Showing 17 changed files with 993 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos-clang-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Install clang
run: brew install llvm@16 && echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/runner/.bash_profile && source /Users/runner/.bash_profile && which clang++
run: brew install llvm@16 && echo 'export PATH="/usr/local/opt/llvm@16/bin:$PATH"' >> /Users/runner/.bash_profile && source /Users/runner/.bash_profile && which clang++

- name: Checkout
uses: actions/checkout@v3
Expand All @@ -26,7 +26,7 @@ jobs:
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@16/bin/clang++
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set(FAKER_SOURCES
src/modules/medicine/Medicine.cpp
src/modules/weather/Weather.cpp
src/common/WeatherHelper.cpp
src/modules/airline/Airline.cpp
)

set(FAKER_UT_SOURCES
Expand Down Expand Up @@ -82,6 +83,7 @@ set(FAKER_UT_SOURCES
src/modules/medicine/MedicineTest.cpp
src/modules/weather/WeatherTest.cpp
src/common/WeatherHelperTest.cpp
src/modules/airline/AirlineTest.cpp
)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES})
Expand Down
140 changes: 140 additions & 0 deletions include/faker-cxx/Airline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#pragma once

#include <string>
#include <vector>

namespace faker {
class Airline {
public:
enum class AircraftType
{
Regional,
Narrowbody,
Widebody,
};

/*
* @brief Get a random aircraft type
*
* @return a random aircraft type
*
* @code
* Airline::aircraftType // "narrowbody"
*/
static std::string aircraftType();

struct Airplane
{
std::string name;
std::string iataTypeCode;
};

/*
* @brief Get a random airplane
*
* @return a random airplane and its iataTypeCode
*
* @code
* Airline::airplane() // {"Boeing 737-800", "738"}
* @endcode
*/
static Airplane airplane();

struct AirlineStruct
{
std::string name;
std::string iataCode;
};

/*
* @brief Get a random airline
*
* @return a random airline and its iataCode
*
* @code
* Airline::airline() // {"Air Canada", "AC"}
* @endcode
*/
static AirlineStruct airline();

struct Airport
{
std::string name;
std::string iataCode;
};

/*
* @brief Get a random airport
*
* @return a random airport and its iataCode
*
* @code
* Airline::airport() // {"Toronto Pearson International Airport", "YYZ"}
* @endcode
*/
static Airport airport();

/*
* @brief Get a random seat by aircraft type
*
* @param aircraftType the aircraft type
*
* @return a random seat
*
* @code
* Airline::seat(AircraftType::Narrowbody) // "1A"
* @endcode
*/
static std::string seat(AircraftType aircraftType);

/*
* @brief Get a random record location
*
* @return a random record location
*
* @code
* Airline::recordLocator() // "ABCDEF"
* Airline::recordLocator(true) // "ABC123"
* @endcode
*/
static std::string recordLocator(bool allowNumerics = false);

/*
* @brief Get a random flight number from given length
*
* @param addLeadingZeros whether to add leading zeros
*
* @param length the length of the flight number
*
* @return a random flight number
*
* @code
* Airline::flightNumber() // "1234"
* Airline::flightNumber(true) // "0123"
* Airline::flightNumber(false, 3) // "234"
* @endcode
*/
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
*
* @param addLeadingZeros whether to add leading zeros
*
* @param length the length of the flight number
*
* @return a random flight number
*
* @code
* Airline::flightNumber() // "1234"
* Airline::flightNumber(true) // "0123"
* Airline::flightNumber(false, {1, 4}) // "234" // "12" // "1234"
* @endcode
*/
static std::string flightNumber(bool addLeadingZeros = false, Range length = {1, 4});
};
}
22 changes: 22 additions & 0 deletions include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ class Internet
*/
static unsigned httpStatusCode(std::optional<HttpResponseType> responseType = std::nullopt);

/**
* @brief Generates a random http request header.
*
* @returns Http request header.
*
* @code
* Internet::httpRequestHeader() // "Authorization"
* @endcode
*/
static std::string httpRequestHeader();

/**
* @brief Generates a random http response header.
*
* @returns Http response header.
*
* @code
* Internet::httpResponseHeader() // "Location"
* @endcode
*/
static std::string httpResponseHeader();

/**
* @brief Returns a string containing randomized ipv4 address of the given class.
*
Expand Down
64 changes: 64 additions & 0 deletions src/modules/airline/Airline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "faker-cxx/Airline.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"

#include <string>

#include "data/AircraftTypes.h"
#include "data/Airplanes.h"
#include "data/Airlines.h"
#include "data/Airports.h"
#include "data/Seat.h"

namespace faker
{
std::string Airline::aircraftType()
{
return Helper::arrayElement<std::string>(aircraftTypes);
}

Airline::Airplane Airline::airplane()
{
return Helper::arrayElement<Airline::Airplane>(airplanes);
}

Airline::AirlineStruct Airline::airline()
{
return Helper::arrayElement<Airline::AirlineStruct>(airlines);
}

Airline::Airport Airline::airport()
{
return Helper::arrayElement<Airline::Airport>(airports);
}

std::string Airline::seat(Airline::AircraftType aircraftType) {
return std::to_string(Number::integer(1, aircraftTypeMaxRows.at(aircraftType))) + Helper::arrayElement<char>(aircraftTypeSeatLetters.at(aircraftType));
}

std::string Airline::recordLocator(bool allowNumerics)
{
if (allowNumerics) {
return String::alphanumeric(6, StringCasing::Upper);
}

return String::alpha(6, StringCasing::Upper);
}

std::string Airline::flightNumber(bool addLeadingZeros, unsigned int length) {
if (addLeadingZeros) {
return String::numeric(length, true);
}

return String::numeric(length, false);
}

std::string Airline::flightNumber(bool addLeadingZeros, Airline::Range length) {
if (addLeadingZeros) {
return String::numeric(Number::integer(length.min, length.max), true);
}

return String::numeric(Number::integer(length.min, length.max), false);
}
}
Loading

0 comments on commit ef3e8b0

Please sign in to comment.