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