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