*/
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE CRSTestSuite
#include <boost/test/unit_test.hpp>
#include <stdair/basic/BasLogParams.hpp>
#include <stdair/basic/BasDBParams.hpp>
#include <stdair/basic/BasFileMgr.hpp>
#include <stdair/bom/TravelSolutionStruct.hpp>
#include <stdair/bom/BookingRequestStruct.hpp>
#include <stdair/service/Logger.hpp>
#include <simfqt/SIMFQT_Types.hpp>
#include <simcrs/config/simcrs-paths.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("CRSTestSuite_utfresults.xml");
struct UnitTestConfig {
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
~UnitTestConfig() {
}
};
const unsigned int testSimCRSHelper (const unsigned short iTestFlag,
const stdair::Filename_T& iScheduleInputFilename,
const stdair::Filename_T& iOnDInputFilename,
const stdair::Filename_T& iFRAT5InputFilename,
const stdair::Filename_T& iFFDisutilityInputFilename,
const stdair::Filename_T& iYieldInputFilename,
const stdair::Filename_T& iFareInputFilename,
const bool isBuiltin,
const unsigned int iExpectedNbOfTravelSolutions,
const unsigned int iExpectedPrice) {
std::ostringstream oStr;
oStr << "CRSTestSuite_" << iTestFlag << ".log";
const stdair::Filename_T lLogFilename (oStr.str());
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
stdair::Date_T lPreferredDepartureDate;;
stdair::Date_T lRequestDate;
stdair::TripType_T lTripType;
if (isBuiltin == true) {
simcrsService.buildSampleBom();
lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
lRequestDate = boost::gregorian::from_string ("2010/01/21");
lTripType = "OW";
} else {
stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
stdair::ODFilePath lODFilePath (iOnDInputFilename);
stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
const SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
const AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
simcrsService.parseAndLoad (lScheduleFilePath, lODFilePath,
lFRAT5FilePath, lFFDisutilityFilePath,
lYieldFilePath, lFareFilePath);
lPreferredDepartureDate = boost::gregorian::from_string ("2011/01/31");
lRequestDate = boost::gregorian::from_string ("2011/01/22");
lTripType = "RI";
}
const stdair::AirportCode_T lOrigin ("SIN");
const stdair::AirportCode_T lDestination ("BKK");
const stdair::AirportCode_T lPOS ("SIN");
const stdair::Duration_T lRequestTime (boost::posix_time::hours(10));
const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
const stdair::CabinCode_T lPreferredCabin ("Eco");
const stdair::PartySize_T lPartySize (3);
const stdair::ChannelLabel_T lChannel ("IN");
const stdair::DayDuration_T lStayDuration (7);
const stdair::FrequentFlyer_T lFrequentFlyerType ("M");
const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
const stdair::WTP_T lWTP (1000.0);
const stdair::PriceValue_T lValueOfTime (100.0);
const stdair::ChangeFees_T lChangeFees (true);
const stdair::Disutility_T lChangeFeeDisutility (50);
const stdair::NonRefundable_T lNonRefundable (true);
const stdair::Disutility_T lNonRefundableDisutility (50);
const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
lPOS,
lPreferredDepartureDate,
lRequestDateTime,
lPreferredCabin,
lPartySize, lChannel,
lTripType, lStayDuration,
lFrequentFlyerType,
lPreferredDepartureTime,
lWTP, lValueOfTime,
lChangeFees,
lChangeFeeDisutility,
lNonRefundable,
lNonRefundableDisutility);
stdair::TravelSolutionList_T lTravelSolutionList =
simcrsService.calculateSegmentPathList (lBookingRequest);
simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
std::ostringstream oMessageKeptTS;
oMessageKeptTS << "The number of travel solutions for the booking request '"
<< lBookingRequest.describe() << "' is actually "
<< lNbOfTravelSolutions << ". That number is expected to be "
<< iExpectedNbOfTravelSolutions << ".";
STDAIR_LOG_DEBUG (oMessageKeptTS.str());
BOOST_CHECK_EQUAL (lNbOfTravelSolutions, iExpectedNbOfTravelSolutions);
BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == iExpectedNbOfTravelSolutions,
oMessageKeptTS.str());
stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
const stdair::FareOptionList_T& lFareOptionList =
lTravelSolution.getFareOptionList();
stdair::FareOptionStruct lFareOption = lFareOptionList.front();
lTravelSolution.setChosenFareOption (lFareOption);
std::ostringstream oMessageKeptFare;
oMessageKeptFare
<< "The price given by the fare quoter for the booking request: '"
<< lBookingRequest.describe() << "' and travel solution: '"
<< lTravelSolution.describe() << "' is actually " << lFareOption.getFare()
<< " Euros. It is expected to be " << iExpectedPrice << " Euros.";
STDAIR_LOG_DEBUG (oMessageKeptFare.str());
BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
== iExpectedPrice, oMessageKeptFare.str());
STDAIR_LOG_DEBUG ("A booking will now (attempted to) be made on the "
"travel solution '" << lTravelSolution.describe()
<< "', for a party size of " << lPartySize << ".");
const bool isSellSuccessful =
simcrsService.sell (lTravelSolution, lPartySize);
logOutputFile.close();
return isSellSuccessful;
}
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
"/rds01/schedule.csv");
"/frat5.csv");
"/ffDisutility.csv");
"/rds01/yield.csv");
"/rds01/fare.csv");
const bool isBuiltin = false;
const unsigned int lExpectedPrice = 400;
const unsigned int lExpectedNbOfTravelSolutions = 1;
bool isSellSuccessful = false;
BOOST_CHECK_NO_THROW (isSellSuccessful =
testSimCRSHelper (0,
lScheduleInputFilename,
lOnDInputFilename,
lFRAT5InputFilename,
lFFDisutilityInputFilename,
lYieldInputFilename,
lFareInputFilename,
isBuiltin,
lExpectedNbOfTravelSolutions,
lExpectedPrice));
std::ostringstream oMessageSell;
const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
STDAIR_LOG_DEBUG (oMessageSell.str());
BOOST_CHECK_EQUAL (isSellSuccessful, true);
BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
}
BOOST_AUTO_TEST_CASE (simcrs_simple_default_bom_simulation_test) {
const bool isBuiltin = true;
const unsigned int lExpectedPrice = 900;
const unsigned int lExpectedNbOfTravelSolutions = 1;
bool isSellSuccessful = false;
BOOST_CHECK_NO_THROW (isSellSuccessful =
testSimCRSHelper (1,
" ", " ", " ", " ", " ", " ",
isBuiltin,
lExpectedNbOfTravelSolutions,
lExpectedPrice));
std::ostringstream oMessageSell;
const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
STDAIR_LOG_DEBUG (oMessageSell.str());
BOOST_CHECK_EQUAL (isSellSuccessful, true);
BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
}
BOOST_AUTO_TEST_SUITE_END()