14 #define BOOST_TEST_DYN_LINK
15 #define BOOST_TEST_MAIN
16 #define BOOST_TEST_MODULE CRSTestSuite
17 #include <boost/test/unit_test.hpp>
19 #include <stdair/basic/BasLogParams.hpp>
20 #include <stdair/basic/BasDBParams.hpp>
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/bom/TravelSolutionStruct.hpp>
23 #include <stdair/bom/BookingRequestStruct.hpp>
24 #include <stdair/service/Logger.hpp>
26 #include <simfqt/SIMFQT_Types.hpp>
29 #include <simcrs/config/simcrs-paths.hpp>
31 namespace boost_utf = boost::unit_test;
34 std::ofstream utfReportStream (
"CRSTestSuite_utfresults.xml");
39 struct UnitTestConfig {
42 boost_utf::unit_test_log.set_stream (utfReportStream);
43 boost_utf::unit_test_log.set_format (boost_utf::XML);
44 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
57 const unsigned int testSimCRSHelper (
const unsigned short iTestFlag,
58 const stdair::Filename_T& iScheduleInputFilename,
59 const stdair::Filename_T& iOnDInputFilename,
60 const stdair::Filename_T& iFRAT5InputFilename,
61 const stdair::Filename_T& iFFDisutilityInputFilename,
62 const stdair::Filename_T& iYieldInputFilename,
63 const stdair::Filename_T& iFareInputFilename,
65 const unsigned int iExpectedNbOfTravelSolutions,
66 const unsigned int iExpectedPrice) {
72 std::ostringstream oStr;
73 oStr <<
"CRSTestSuite_" << iTestFlag <<
".log";
74 const stdair::Filename_T lLogFilename (oStr.str());
77 std::ofstream logOutputFile;
79 logOutputFile.open (lLogFilename.c_str());
80 logOutputFile.clear();
83 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
86 stdair::Date_T lPreferredDepartureDate;;
87 stdair::Date_T lRequestDate;
88 stdair::TripType_T lTripType;
91 if (isBuiltin ==
true) {
94 simcrsService.buildSampleBom();
96 lPreferredDepartureDate = boost::gregorian::from_string (
"2010/02/08");
97 lRequestDate = boost::gregorian::from_string (
"2010/01/21");
103 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
104 stdair::ODFilePath lODFilePath (iOnDInputFilename);
105 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
106 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
107 const SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
108 const AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
109 simcrsService.parseAndLoad (lScheduleFilePath, lODFilePath,
110 lFRAT5FilePath, lFFDisutilityFilePath,
111 lYieldFilePath, lFareFilePath);
113 lPreferredDepartureDate = boost::gregorian::from_string (
"2011/01/31");
114 lRequestDate = boost::gregorian::from_string (
"2011/01/22");
119 const stdair::AirportCode_T lOrigin (
"SIN");
120 const stdair::AirportCode_T lDestination (
"BKK");
121 const stdair::AirportCode_T lPOS (
"SIN");
122 const stdair::Duration_T lRequestTime (boost::posix_time::hours(10));
123 const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
124 const stdair::CabinCode_T lPreferredCabin (
"Eco");
125 const stdair::PartySize_T lPartySize (3);
126 const stdair::ChannelLabel_T lChannel (
"IN");
127 const stdair::DayDuration_T lStayDuration (7);
128 const stdair::FrequentFlyer_T lFrequentFlyerType (
"M");
129 const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
130 const stdair::WTP_T lWTP (1000.0);
131 const stdair::PriceValue_T lValueOfTime (100.0);
132 const stdair::ChangeFees_T lChangeFees (
true);
133 const stdair::Disutility_T lChangeFeeDisutility (50);
134 const stdair::NonRefundable_T lNonRefundable (
true);
135 const stdair::Disutility_T lNonRefundableDisutility (50);
136 const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
138 lPreferredDepartureDate,
141 lPartySize, lChannel,
142 lTripType, lStayDuration,
144 lPreferredDepartureTime,
147 lChangeFeeDisutility,
149 lNonRefundableDisutility);
150 stdair::TravelSolutionList_T lTravelSolutionList =
151 simcrsService.calculateSegmentPathList (lBookingRequest);
154 simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
157 const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
160 std::ostringstream oMessageKeptTS;
161 oMessageKeptTS <<
"The number of travel solutions for the booking request '"
162 << lBookingRequest.describe() <<
"' is actually "
163 << lNbOfTravelSolutions <<
". That number is expected to be "
164 << iExpectedNbOfTravelSolutions <<
".";
165 STDAIR_LOG_DEBUG (oMessageKeptTS.str());
167 BOOST_CHECK_EQUAL (lNbOfTravelSolutions, iExpectedNbOfTravelSolutions);
169 BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == iExpectedNbOfTravelSolutions,
170 oMessageKeptTS.str());
176 stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
182 const stdair::FareOptionList_T& lFareOptionList =
183 lTravelSolution.getFareOptionList();
193 stdair::FareOptionStruct lFareOption = lFareOptionList.front();
194 lTravelSolution.setChosenFareOption (lFareOption);
197 std::ostringstream oMessageKeptFare;
199 <<
"The price given by the fare quoter for the booking request: '"
200 << lBookingRequest.describe() <<
"' and travel solution: '"
201 << lTravelSolution.describe() <<
"' is actually " << lFareOption.getFare()
202 <<
" Euros. It is expected to be " << iExpectedPrice <<
" Euros.";
203 STDAIR_LOG_DEBUG (oMessageKeptFare.str());
205 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
207 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
208 == iExpectedPrice, oMessageKeptFare.str());
218 STDAIR_LOG_DEBUG (
"A booking will now (attempted to) be made on the "
219 "travel solution '" << lTravelSolution.describe()
220 <<
"', for a party size of " << lPartySize <<
".");
222 const bool isSellSuccessful =
223 simcrsService.sell (lTravelSolution, lPartySize);
226 logOutputFile.close();
228 return isSellSuccessful;
236 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
239 BOOST_AUTO_TEST_SUITE (master_test_suite)
244 BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
248 "/rds01/schedule.csv");
259 "/ffDisutility.csv");
270 const bool isBuiltin =
false;
277 const unsigned int lExpectedPrice = 400;
278 const unsigned int lExpectedNbOfTravelSolutions = 1;
280 bool isSellSuccessful =
false;
282 BOOST_CHECK_NO_THROW (isSellSuccessful =
284 lScheduleInputFilename,
287 lFFDisutilityInputFilename,
291 lExpectedNbOfTravelSolutions,
295 std::ostringstream oMessageSell;
296 const std::string isSellSuccessfulStr = (isSellSuccessful ==
true)?
"Yes":
"No";
297 oMessageSell <<
"Was the sell successful? Answer: " << isSellSuccessfulStr;
298 STDAIR_LOG_DEBUG (oMessageSell.str());
300 BOOST_CHECK_EQUAL (isSellSuccessful,
true);
302 BOOST_CHECK_MESSAGE (isSellSuccessful ==
true, oMessageSell.str());
311 BOOST_AUTO_TEST_CASE (simcrs_simple_default_bom_simulation_test) {
314 const bool isBuiltin =
true;
321 const unsigned int lExpectedPrice = 900;
322 const unsigned int lExpectedNbOfTravelSolutions = 1;
324 bool isSellSuccessful =
false;
326 BOOST_CHECK_NO_THROW (isSellSuccessful =
328 " ",
" ",
" ",
" ",
" ",
" ",
330 lExpectedNbOfTravelSolutions,
334 std::ostringstream oMessageSell;
335 const std::string isSellSuccessfulStr = (isSellSuccessful ==
true)?
"Yes":
"No";
336 oMessageSell <<
"Was the sell successful? Answer: " << isSellSuccessfulStr;
337 STDAIR_LOG_DEBUG (oMessageSell.str());
339 BOOST_CHECK_EQUAL (isSellSuccessful,
true);
341 BOOST_CHECK_MESSAGE (isSellSuccessful ==
true, oMessageSell.str());
347 BOOST_AUTO_TEST_SUITE_END()