SimCRS Logo  1.00.0
C++ Simulated Travel-Oriented Distribution System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
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  boost_utf::unit_test_log.set_format (boost_utf::XML);
44  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
45  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
46  }
47 
49  ~UnitTestConfig() {
50  }
51 };
52 
53 // //////////////////////////////////////////////////////////////////////
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,
64  const bool isBuiltin,
65  const unsigned int iExpectedNbOfTravelSolutions,
66  const unsigned int iExpectedPrice) {
67 
68  // CRS code
69  const SIMCRS::CRSCode_T lCRSCode ("1P");
70 
71  // Output log File
72  std::ostringstream oStr;
73  oStr << "CRSTestSuite_" << iTestFlag << ".log";
74  const stdair::Filename_T lLogFilename (oStr.str());
75 
76  // Set the log parameters
77  std::ofstream logOutputFile;
78  // Open and clean the log outputfile
79  logOutputFile.open (lLogFilename.c_str());
80  logOutputFile.clear();
81 
82  // Initialise the list of classes/buckets
83  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
84  SIMCRS::SIMCRS_Service simcrsService (lLogParams, lCRSCode);
85 
86  stdair::Date_T lPreferredDepartureDate;;
87  stdair::Date_T lRequestDate;
88  stdair::TripType_T lTripType;
89 
90  // Check wether or not a (CSV) input file should be read
91  if (isBuiltin == true) {
92 
93  // Build the default sample BOM tree
94  simcrsService.buildSampleBom();
95 
96  lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
97  lRequestDate = boost::gregorian::from_string ("2010/01/21");
98  lTripType = "OW";
99 
100  } else {
101 
102  // Build the BOM tree from parsing input files
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);
112 
113  lPreferredDepartureDate = boost::gregorian::from_string ("2011/01/31");
114  lRequestDate = boost::gregorian::from_string ("2011/01/22");
115  lTripType = "RI";
116  }
117 
118  // Create an empty booking request structure
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,
137  lPOS,
138  lPreferredDepartureDate,
139  lRequestDateTime,
140  lPreferredCabin,
141  lPartySize, lChannel,
142  lTripType, lStayDuration,
143  lFrequentFlyerType,
144  lPreferredDepartureTime,
145  lWTP, lValueOfTime,
146  lChangeFees,
147  lChangeFeeDisutility,
148  lNonRefundable,
149  lNonRefundableDisutility);
150  stdair::TravelSolutionList_T lTravelSolutionList =
151  simcrsService.calculateSegmentPathList (lBookingRequest);
152 
153  // Price the travel solution
154  simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
155 
156  //
157  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
158 
159  // DEBUG
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());
166 
167  BOOST_CHECK_EQUAL (lNbOfTravelSolutions, iExpectedNbOfTravelSolutions);
168 
169  BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == iExpectedNbOfTravelSolutions,
170  oMessageKeptTS.str());
171 
176  stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
177 
182  const stdair::FareOptionList_T& lFareOptionList =
183  lTravelSolution.getFareOptionList();
184 
193  stdair::FareOptionStruct lFareOption = lFareOptionList.front();
194  lTravelSolution.setChosenFareOption (lFareOption);
195 
196  // DEBUG
197  std::ostringstream oMessageKeptFare;
198  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());
204 
205  BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
206 
207  BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
208  == iExpectedPrice, oMessageKeptFare.str());
209 
217  // DEBUG
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 << ".");
221 
222  const bool isSellSuccessful =
223  simcrsService.sell (lTravelSolution, lPartySize);
224 
225  // Close the log file
226  logOutputFile.close();
227 
228  return isSellSuccessful;
229 
230 }
231 
232 
233 // /////////////// Main: Unit Test Suite //////////////
234 
235 // Set the UTF configuration (re-direct the output to a specific file)
236 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
237 
238 // Start the test suite
239 BOOST_AUTO_TEST_SUITE (master_test_suite)
240 
241 
244 BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
245 
246  // Schedule input filename
247  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
248  "/rds01/schedule.csv");
249 
250  // O&D input filename
251  const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/ond01.csv");
252 
253  // FRAT5 curve input file name
254  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
255  "/frat5.csv");
256 
257  // Fare family disutility curve input file name
258  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
259  "/ffDisutility.csv");
260 
261  // Yield input filename
262  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
263  "/rds01/yield.csv");
264 
265  // Fare input filename
266  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR
267  "/rds01/fare.csv");
268 
269  // State whether the BOM tree should be built-in or parsed from input files
270  const bool isBuiltin = false;
271 
277  const unsigned int lExpectedPrice = 400;
278  const unsigned int lExpectedNbOfTravelSolutions = 1;
279 
280  bool isSellSuccessful = false;
281 
282  BOOST_CHECK_NO_THROW (isSellSuccessful =
283  testSimCRSHelper (0,
284  lScheduleInputFilename,
285  lOnDInputFilename,
286  lFRAT5InputFilename,
287  lFFDisutilityInputFilename,
288  lYieldInputFilename,
289  lFareInputFilename,
290  isBuiltin,
291  lExpectedNbOfTravelSolutions,
292  lExpectedPrice));
293 
294  // DEBUG
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());
299 
300  BOOST_CHECK_EQUAL (isSellSuccessful, true);
301 
302  BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
303 
304 
305 }
306 
307 
311 BOOST_AUTO_TEST_CASE (simcrs_simple_default_bom_simulation_test) {
312 
313  // State whether the BOM tree should be built-in or parsed from input files
314  const bool isBuiltin = true;
315 
321  const unsigned int lExpectedPrice = 900;
322  const unsigned int lExpectedNbOfTravelSolutions = 1;
323 
324  bool isSellSuccessful = false;
325 
326  BOOST_CHECK_NO_THROW (isSellSuccessful =
327  testSimCRSHelper (1,
328  " ", " ", " ", " ", " ", " ",
329  isBuiltin,
330  lExpectedNbOfTravelSolutions,
331  lExpectedPrice));
332 
333  // DEBUG
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());
338 
339  BOOST_CHECK_EQUAL (isSellSuccessful, true);
340 
341  BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
342 
343 
344 }
345 
346 // End the test suite
347 BOOST_AUTO_TEST_SUITE_END()
348 
349