SimCRS Logo  0.1.1
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
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 
54 // /////////////// Main: Unit Test Suite //////////////
55 
56 // Set the UTF configuration (re-direct the output to a specific file)
57 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
58 
59 // Start the test suite
60 BOOST_AUTO_TEST_SUITE (master_test_suite)
61 
62 
65 BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
66 
67  // CRS code
68  const SIMCRS::CRSCode_T lCRSCode ("1P");
69 
70  // Schedule input filename
71  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
72  "/rds01/schedule.csv");
73 
74  // O&D input filename
75  const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/ond01.csv");
76 
77  // Yield input filename
78  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
79  "/rds01/yield.csv");
80 
81  // Fare input filename
82  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR
83  "/rds01/fare.csv");
84 
85  // Check that the file path given as input corresponds to an actual file
86  bool doesExistAndIsReadable =
87  stdair::BasFileMgr::doesExistAndIsReadable (lScheduleInputFilename);
88  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
89  "The '" << lScheduleInputFilename
90  << "' input file can not be open and read");
91 
92  // Check that the file path given as input corresponds to an actual file
93  doesExistAndIsReadable =
94  stdair::BasFileMgr::doesExistAndIsReadable (lOnDInputFilename);
95  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
96  "The '" << lOnDInputFilename
97  << "' input file can not be open and read");
98 
99  // Check that the file path given as input corresponds to an actual file
100  doesExistAndIsReadable =
101  stdair::BasFileMgr::doesExistAndIsReadable (lYieldInputFilename);
102  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
103  "The '" << lYieldInputFilename
104  << "' input file can not be open and read");
105 
106  // Check that the file path given as input corresponds to an actual file
107  doesExistAndIsReadable =
108  stdair::BasFileMgr::doesExistAndIsReadable (lFareInputFilename);
109  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
110  "The '" << lFareInputFilename
111  << "' input file can not be open and read");
112 
113  // Output log File
114  const stdair::Filename_T lLogFilename ("CRSTestSuite.log");
115 
116  // Set the log parameters
117  std::ofstream logOutputFile;
118  // Open and clean the log outputfile
119  logOutputFile.open (lLogFilename.c_str());
120  logOutputFile.clear();
121 
122  // Initialise the list of classes/buckets
123  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
124  SIMCRS::SIMCRS_Service simcrsService (lLogParams, lCRSCode);
125 
126  // Build the BOM tree from parsing input files
127  const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
128  const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
129  simcrsService.parseAndLoad (lScheduleInputFilename, lOnDInputFilename,
130  lYieldFilePath, lFareFilePath);
131 
132  // Create an empty booking request structure
133  // TODO: fill the booking request structure from the input parameters
134  const stdair::AirportCode_T lOrigin ("SIN");
135  const stdair::AirportCode_T lDestination ("BKK");
136  const stdair::AirportCode_T lPOS ("SIN");
137  const stdair::Date_T lPreferredDepartureDate(2011, boost::gregorian::Jan, 31);
138  const stdair::Date_T lRequestDate (2011, boost::gregorian::Jan, 22);
139  const stdair::Duration_T lRequestTime (boost::posix_time::hours(10));
140  const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
141  const stdair::CabinCode_T lPreferredCabin ("Eco");
142  const stdair::PartySize_T lPartySize (3);
143  const stdair::ChannelLabel_T lChannel ("IN");
144  const stdair::TripType_T lTripType ("RI");
145  const stdair::DayDuration_T lStayDuration (7);
146  const stdair::FrequentFlyer_T lFrequentFlyerType ("M");
147  const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
148  const stdair::WTP_T lWTP (1000.0);
149  const stdair::PriceValue_T lValueOfTime (100.0);
150  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
151  lPOS,
152  lPreferredDepartureDate,
153  lRequestDateTime,
154  lPreferredCabin,
155  lPartySize, lChannel,
156  lTripType, lStayDuration,
157  lFrequentFlyerType,
158  lPreferredDepartureTime,
159  lWTP, lValueOfTime);
160  stdair::TravelSolutionList_T lTravelSolutionList =
161  simcrsService.calculateSegmentPathList (lBookingRequest);
162 
163  // Price the travel solution
164  simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
165 
166  //
167  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
168 
169  // \todo change the expected number of travel solutions to the actual number
170  const unsigned int lExpectedNbOfTravelSolutions = 1;
171 
172  // DEBUG
173  std::ostringstream oMessageKeptTS;
174  oMessageKeptTS << "The number of travel solutions for the booking request '"
175  << lBookingRequest.describe() << "' is actually "
176  << lNbOfTravelSolutions << ". That number is expected to be "
177  << lExpectedNbOfTravelSolutions << ".";
178  STDAIR_LOG_DEBUG (oMessageKeptTS.str());
179 
180  BOOST_CHECK_EQUAL (lNbOfTravelSolutions, lExpectedNbOfTravelSolutions);
181 
182  BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
183  oMessageKeptTS.str());
184 
189  stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
190 
195  const stdair::FareOptionList_T& lFareOptionList =
196  lTravelSolution.getFareOptionList();
197 
206  stdair::FareOptionStruct lFareOption = lFareOptionList.front();
207  lTravelSolution.setChosenFareOption (lFareOption);
208 
214  const unsigned int lExpectedPrice = 400;
215 
216  // DEBUG
217  std::ostringstream oMessageKeptFare;
218  oMessageKeptFare
219  << "The price given by the fare quoter for the booking request: '"
220  << lBookingRequest.describe() << "' and travel solution: '"
221  << lTravelSolution.describe() << "' is actually " << lFareOption.getFare()
222  << " Euros. It is expected to be " << lExpectedPrice << " Euros.";
223  STDAIR_LOG_DEBUG (oMessageKeptFare.str());
224 
225  BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), lExpectedPrice);
226 
227  BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
228  == lExpectedPrice, oMessageKeptFare.str());
229 
237  // DEBUG
238  STDAIR_LOG_DEBUG ("A booking will now (attempted to) be made on the "
239  "travel solution '" << lTravelSolution.describe()
240  << "', for a party size of " << lPartySize << ".");
241 
242  const bool isSellSuccessful =
243  simcrsService.sell (lTravelSolution, lPartySize);
244  //BOOST_CHECK_NO_THROW ();
245 
246  // DEBUG
247  std::ostringstream oMessageSell;
248  const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
249  oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
250  STDAIR_LOG_DEBUG (oMessageSell.str());
251 
252  BOOST_CHECK_EQUAL (isSellSuccessful, true);
253 
254  BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
255 
256  // Close the log file
257  logOutputFile.close();
258 }
259 
260 // End the test suite
261 BOOST_AUTO_TEST_SUITE_END()
262 
263