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