SimCRS Logo  1.01.1
C++ Simulated Travel-Oriented Distribution System Library
CRSTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 #include <cmath>
13 // Boost Unit Test Framework (UTF)
14 #define BOOST_TEST_DYN_LINK
15 #define BOOST_TEST_MAIN
16 #define BOOST_TEST_MODULE CRSTestSuite
17 #include <boost/test/unit_test.hpp>
18 #include <boost/version.hpp>
19 // StdAir
20 #include <stdair/basic/BasLogParams.hpp>
21 #include <stdair/basic/BasDBParams.hpp>
22 #include <stdair/basic/BasFileMgr.hpp>
23 #include <stdair/bom/TravelSolutionStruct.hpp>
24 #include <stdair/bom/BookingRequestStruct.hpp>
25 #include <stdair/service/Logger.hpp>
26 // SimFQT
27 #include <simfqt/SIMFQT_Types.hpp>
28 // SimCRS
31 
32 namespace boost_utf = boost::unit_test;
33 
34 // (Boost) Unit Test XML Report
35 std::ofstream utfReportStream ("CRSTestSuite_utfresults.xml");
36 
40 struct UnitTestConfig {
42  UnitTestConfig() {
43  boost_utf::unit_test_log.set_stream (utfReportStream);
44 #if BOOST_VERSION >= 105900
45  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
46 #else
47  boost_utf::unit_test_log.set_format (boost_utf::XML);
48 #endif
49  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
50  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
51  }
52 
54  ~UnitTestConfig() {
55  }
56 };
57 
58 // //////////////////////////////////////////////////////////////////////
62 const unsigned int testSimCRSHelper (const unsigned short iTestFlag,
63  const stdair::Filename_T& iScheduleInputFilename,
64  const stdair::Filename_T& iOnDInputFilename,
65  const stdair::Filename_T& iFRAT5InputFilename,
66  const stdair::Filename_T& iFFDisutilityInputFilename,
67  const stdair::Filename_T& iYieldInputFilename,
68  const stdair::Filename_T& iFareInputFilename,
69  const bool isBuiltin,
70  const unsigned int iExpectedNbOfTravelSolutions,
71  const unsigned int iExpectedPrice) {
72 
73  // CRS code
74  const SIMCRS::CRSCode_T lCRSCode ("1P");
75 
76  // Output log File
77  std::ostringstream oStr;
78  oStr << "CRSTestSuite_" << iTestFlag << ".log";
79  const stdair::Filename_T lLogFilename (oStr.str());
80 
81  // Set the log parameters
82  std::ofstream logOutputFile;
83  // Open and clean the log outputfile
84  logOutputFile.open (lLogFilename.c_str());
85  logOutputFile.clear();
86 
87  // Initialise the list of classes/buckets
88  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
89  SIMCRS::SIMCRS_Service simcrsService (lLogParams, lCRSCode);
90 
91  stdair::Date_T lPreferredDepartureDate;;
92  stdair::Date_T lRequestDate;
93  stdair::TripType_T lTripType;
94 
95  // Check wether or not a (CSV) input file should be read
96  if (isBuiltin == true) {
97 
98  // Build the default sample BOM tree
99  simcrsService.buildSampleBom();
100 
101  lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
102  lRequestDate = boost::gregorian::from_string ("2010/01/21");
103  lTripType = "OW";
104 
105  } else {
106 
107  // Build the BOM tree from parsing input files
108  stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
109  stdair::ODFilePath lODFilePath (iOnDInputFilename);
110  stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
111  stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
112  const SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
113  const AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
114  simcrsService.parseAndLoad (lScheduleFilePath, lODFilePath,
115  lFRAT5FilePath, lFFDisutilityFilePath,
116  lYieldFilePath, lFareFilePath);
117 
118  lPreferredDepartureDate = boost::gregorian::from_string ("2011/01/31");
119  lRequestDate = boost::gregorian::from_string ("2011/01/22");
120  lTripType = "RI";
121  }
122 
123  // Create an empty booking request structure
124  const stdair::AirportCode_T lOrigin ("SIN");
125  const stdair::AirportCode_T lDestination ("BKK");
126  const stdair::AirportCode_T lPOS ("SIN");
127  const stdair::Duration_T lRequestTime (boost::posix_time::hours(10));
128  const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
129  const stdair::CabinCode_T lPreferredCabin ("Eco");
130  const stdair::PartySize_T lPartySize (3);
131  const stdair::ChannelLabel_T lChannel ("IN");
132  const stdair::DayDuration_T lStayDuration (7);
133  const stdair::FrequentFlyer_T lFrequentFlyerType ("M");
134  const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
135  const stdair::WTP_T lWTP (1000.0);
136  const stdair::PriceValue_T lValueOfTime (100.0);
137  const stdair::ChangeFees_T lChangeFees (true);
138  const stdair::Disutility_T lChangeFeeDisutility (50);
139  const stdair::NonRefundable_T lNonRefundable (true);
140  const stdair::Disutility_T lNonRefundableDisutility (50);
141  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
142  lPOS,
143  lPreferredDepartureDate,
144  lRequestDateTime,
145  lPreferredCabin,
146  lPartySize, lChannel,
147  lTripType, lStayDuration,
148  lFrequentFlyerType,
149  lPreferredDepartureTime,
150  lWTP, lValueOfTime,
151  lChangeFees,
152  lChangeFeeDisutility,
153  lNonRefundable,
154  lNonRefundableDisutility);
155  stdair::TravelSolutionList_T lTravelSolutionList =
156  simcrsService.calculateSegmentPathList (lBookingRequest);
157 
158  // Price the travel solution
159  simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
160 
161  //
162  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
163 
164  // DEBUG
165  std::ostringstream oMessageKeptTS;
166  oMessageKeptTS << "The number of travel solutions for the booking request '"
167  << lBookingRequest.describe() << "' is actually "
168  << lNbOfTravelSolutions << ". That number is expected to be "
169  << iExpectedNbOfTravelSolutions << ".";
170  STDAIR_LOG_DEBUG (oMessageKeptTS.str());
171 
172  BOOST_CHECK_EQUAL (lNbOfTravelSolutions, iExpectedNbOfTravelSolutions);
173 
174  BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == iExpectedNbOfTravelSolutions,
175  oMessageKeptTS.str());
176 
181  stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
182 
187  const stdair::FareOptionList_T& lFareOptionList =
188  lTravelSolution.getFareOptionList();
189 
198  stdair::FareOptionStruct lFareOption = lFareOptionList.front();
199  lTravelSolution.setChosenFareOption (lFareOption);
200 
201  // DEBUG
202  std::ostringstream oMessageKeptFare;
203  oMessageKeptFare
204  << "The price given by the fare quoter for the booking request: '"
205  << lBookingRequest.describe() << "' and travel solution: '"
206  << lTravelSolution.describe() << "' is actually " << lFareOption.getFare()
207  << " Euros. It is expected to be " << iExpectedPrice << " Euros.";
208  STDAIR_LOG_DEBUG (oMessageKeptFare.str());
209 
210  BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
211 
212  BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
213  == iExpectedPrice, oMessageKeptFare.str());
214 
222  // DEBUG
223  STDAIR_LOG_DEBUG ("A booking will now (attempted to) be made on the "
224  "travel solution '" << lTravelSolution.describe()
225  << "', for a party size of " << lPartySize << ".");
226 
227  const bool isSellSuccessful =
228  simcrsService.sell (lTravelSolution, lPartySize);
229 
230  // Close the log file
231  logOutputFile.close();
232 
233  return isSellSuccessful;
234 
235 }
236 
237 
238 // /////////////// Main: Unit Test Suite //////////////
239 
240 // Set the UTF configuration (re-direct the output to a specific file)
241 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
242 
243 // Start the test suite
244 BOOST_AUTO_TEST_SUITE (master_test_suite)
245 
246 
249 BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
250 
251  // Schedule input filename
252  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
253  "/rds01/schedule.csv");
254 
255  // O&D input filename
256  const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/ond01.csv");
257 
258  // FRAT5 curve input file name
259  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
260  "/frat5.csv");
261 
262  // Fare family disutility curve input file name
263  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
264  "/ffDisutility.csv");
265 
266  // Yield input filename
267  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
268  "/rds01/yield.csv");
269 
270  // Fare input filename
271  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR
272  "/rds01/fare.csv");
273 
274  // State whether the BOM tree should be built-in or parsed from input files
275  const bool isBuiltin = false;
276 
282  const unsigned int lExpectedPrice = 400;
283  const unsigned int lExpectedNbOfTravelSolutions = 1;
284 
285  bool isSellSuccessful = false;
286 
287  BOOST_CHECK_NO_THROW (isSellSuccessful =
288  testSimCRSHelper (0,
289  lScheduleInputFilename,
290  lOnDInputFilename,
291  lFRAT5InputFilename,
292  lFFDisutilityInputFilename,
293  lYieldInputFilename,
294  lFareInputFilename,
295  isBuiltin,
296  lExpectedNbOfTravelSolutions,
297  lExpectedPrice));
298 
299  // DEBUG
300  std::ostringstream oMessageSell;
301  const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
302  oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
303  STDAIR_LOG_DEBUG (oMessageSell.str());
304 
305  BOOST_CHECK_EQUAL (isSellSuccessful, true);
306 
307  BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
308 
309 
310 }
311 
312 
316 BOOST_AUTO_TEST_CASE (simcrs_simple_default_bom_simulation_test) {
317 
318  // State whether the BOM tree should be built-in or parsed from input files
319  const bool isBuiltin = true;
320 
326  const unsigned int lExpectedPrice = 900;
327  const unsigned int lExpectedNbOfTravelSolutions = 1;
328 
329  bool isSellSuccessful = false;
330 
331  BOOST_CHECK_NO_THROW (isSellSuccessful =
332  testSimCRSHelper (1,
333  " ", " ", " ", " ", " ", " ",
334  isBuiltin,
335  lExpectedNbOfTravelSolutions,
336  lExpectedPrice));
337 
338  // DEBUG
339  std::ostringstream oMessageSell;
340  const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
341  oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
342  STDAIR_LOG_DEBUG (oMessageSell.str());
343 
344  BOOST_CHECK_EQUAL (isSellSuccessful, true);
345 
346  BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
347 
348 
349 }
350 
351 // End the test suite
352 BOOST_AUTO_TEST_SUITE_END()
353 
354 
std::string CRSCode_T
#define STDAIR_SAMPLE_DIR