TravelCCM Logo  1.00.2
C++ Travel Customer Choice Model Library
TravelChoiceTestSuite.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 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE TravelCCMTest
16 #include <boost/test/unit_test.hpp>
17 // StdAir
18 #include <stdair/basic/BasLogParams.hpp>
19 #include <stdair/basic/BasDBParams.hpp>
20 #include <stdair/basic/BasFileMgr.hpp>
21 #include <stdair/basic/PassengerChoiceModel.hpp>
22 #include <stdair/bom/TravelSolutionStruct.hpp>
23 #include <stdair/bom/BookingRequestStruct.hpp>
24 #include <stdair/service/Logger.hpp>
25 // TravelCCM
28 
29 namespace boost_utf = boost::unit_test;
30 
31 // (Boost) Unit Test XML Report
32 std::ofstream utfReportStream ("TravelChoiceTestSuite_utfresults.xml");
33 
37 struct UnitTestConfig {
39  UnitTestConfig() {
40  boost_utf::unit_test_log.set_stream (utfReportStream);
41  boost_utf::unit_test_log.set_format (boost_utf::XML);
42  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
43  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
44  }
46  ~UnitTestConfig() {
47  }
48 };
49 
50 // //////////////////////////////////////////////////////////////////////
54 void testTravelCCMHelper (const unsigned short iTestFlag,
55  const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
56  const unsigned int iExpectedPrice) {
57 
58  // Output log File
59  std::ostringstream oStr;
60  oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log";
61  const stdair::Filename_T lLogFilename (oStr.str());
62 
63  // Set the log parameters
64  std::ofstream logOutputFile;
65  // Open and clean the log outputfile
66  logOutputFile.open (lLogFilename.c_str());
67  logOutputFile.clear();
68 
69  // Initialise the service context
70  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
71 
72  // Build the BOM tree
73  TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
74  travelccmService.buildSampleBom ();
75 
76  // DEBUG
77  STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
78 
79  // Build a list of travel solutions
80  const stdair::BookingRequestStruct& lBookingRequest =
81  travelccmService.buildSampleBookingRequest();
82 
83  // DEBUG
84  STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
85 
86  // Build the sample BOM tree
87  stdair::TravelSolutionList_T lTSList;
88  travelccmService.buildSampleTravelSolutions (lTSList);
89 
90  // DEBUG: Display the list of travel solutions
91  const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
92  STDAIR_LOG_DEBUG (lCSVDump);
93 
94  // Choose a travel solution
95  const stdair::TravelSolutionStruct* lTS_ptr =
96  travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
97 
98  // Check that a solution has been found
99  BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
100  "No travel solution can be found for "
101  << lBookingRequest.display()
102  << " within the following list of travel solutions. "
103  << lCSVDump);
104 
105  STDAIR_LOG_DEBUG (lTS_ptr->describe());
106 
107  // Retrieve the chosen fare option
108  stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
109 
110  // DEBUG
111  std::ostringstream oMessageExpectedPrice;
112  oMessageExpectedPrice << "The price chosen by the passenger is: "
113  << lFareOption.getFare() << " Euros. It is expected to be "
114  << iExpectedPrice << " Euros.";
115  STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());
116 
117  // Check that the price corresponds to the expected one
118  BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
119 
120  BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
121  == iExpectedPrice, oMessageExpectedPrice.str());
122 
123  // Close the log file
124  logOutputFile.close();
125 
126 }
127 
131 void testAllTravelCCMHelper (const unsigned short iTestFlag) {
132 
133  // Output log File
134  std::ostringstream oStr;
135  oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log";
136  const stdair::Filename_T lLogFilename (oStr.str());
137 
138  // Set the log parameters
139  std::ofstream logOutputFile;
140  // Open and clean the log outputfile
141  logOutputFile.open (lLogFilename.c_str());
142  logOutputFile.clear();
143 
144  // Initialise the service context
145  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
146 
147  // Build the BOM tree
148  TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
149  travelccmService.buildSampleBom ();
150 
151  // DEBUG
152  STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
153 
154  // Build a list of travel solutions
155  const stdair::BookingRequestStruct& lBookingRequest =
156  travelccmService.buildSampleBookingRequest();
157 
158  // DEBUG
159  STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
160 
161  // Build the sample BOM tree
162  stdair::TravelSolutionList_T lTSList;
163  travelccmService.buildSampleTravelSolutions (lTSList);
164 
165  // DEBUG: Display the list of travel solutions
166  const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
167  STDAIR_LOG_DEBUG (lCSVDump);
168 
169  // Choose a travel solution with the hard restriction method.
170  const stdair::TravelSolutionStruct* lTS_HardRestriction_ptr =
171  travelccmService.chooseTravelSolution
172  (lTSList, lBookingRequest,
173  stdair::PassengerChoiceModel::HARD_RESTRICTION);
174 
175  STDAIR_LOG_DEBUG ("Chosen travel solution with the Hard Restriction model: "
176  + lTS_HardRestriction_ptr->describe());
177 
178  // Choose a travel solution with the price oriented model
179  const stdair::TravelSolutionStruct* lTS_Price_Oriented_ptr =
180  travelccmService.chooseTravelSolution
181  (lTSList, lBookingRequest,
182  stdair::PassengerChoiceModel::PRICE_ORIENTED);
183 
184  STDAIR_LOG_DEBUG ("Chosen travel solution with the Price Oriented model: "
185  + lTS_Price_Oriented_ptr->describe());
186 
187  // Choose a travel solution with the hybrid model
188  const stdair::TravelSolutionStruct* lTS_Hybrid_ptr =
189  travelccmService.chooseTravelSolution
190  (lTSList, lBookingRequest,
191  stdair::PassengerChoiceModel::HYBRID);
192 
193  STDAIR_LOG_DEBUG ("Chosen travel solution with the Hybrid model: " +
194  lTS_Hybrid_ptr->describe());
195 
196  // Close the log file
197  logOutputFile.close();
198 
199 }
200 
201 
202 // /////////////// Main: Unit Test Suite //////////////
203 
204 // Set the UTF configuration (re-direct the output to a specific file)
205 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
206 
207 // Start the test suite
208 BOOST_AUTO_TEST_SUITE (master_test_suite)
209 
210 
213 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
214 
219  const unsigned int lExpectedPrice = 1000;
220 
221  BOOST_CHECK_NO_THROW (testTravelCCMHelper
222  (0,
223  stdair::PassengerChoiceModel::HARD_RESTRICTION,
224  lExpectedPrice));
225 }
226 
230 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
231 
236  const unsigned int lExpectedPrice = 900;
237 
238  BOOST_CHECK_NO_THROW (testTravelCCMHelper
239  (1,
240  stdair::PassengerChoiceModel::PRICE_ORIENTED,
241  lExpectedPrice));
242 }
243 
247 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
248 
253  const unsigned int lExpectedPrice = 920;
254 
255  BOOST_CHECK_NO_THROW (testTravelCCMHelper
256  (2,
257  stdair::PassengerChoiceModel::HYBRID,
258  lExpectedPrice));
259 }
260 
264 BOOST_AUTO_TEST_CASE (all_models_test) {
265 
266  BOOST_CHECK_NO_THROW (testAllTravelCCMHelper(3));
267 }
268 
269 // End the test suite
270 BOOST_AUTO_TEST_SUITE_END()
271 
272