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> 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> 30 namespace boost_utf = boost::unit_test;
33 std::ofstream utfReportStream (
"TravelChoiceTestSuite_utfresults.xml");
38 struct 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);
45 boost_utf::unit_test_log.set_format (boost_utf::XML);
47 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
59 void testTravelCCMHelper (
const unsigned short iTestFlag,
60 const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
61 const unsigned int iExpectedPrice) {
64 std::ostringstream oStr;
65 oStr <<
"TravelChoiceTestSuite_" << iTestFlag <<
".log";
66 const stdair::Filename_T lLogFilename (oStr.str());
69 std::ofstream logOutputFile;
71 logOutputFile.open (lLogFilename.c_str());
72 logOutputFile.clear();
75 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
79 travelccmService.buildSampleBom ();
82 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
85 const stdair::BookingRequestStruct& lBookingRequest =
86 travelccmService.buildSampleBookingRequest();
89 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
92 stdair::TravelSolutionList_T lTSList;
93 travelccmService.buildSampleTravelSolutions (lTSList);
96 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
97 STDAIR_LOG_DEBUG (lCSVDump);
100 const stdair::TravelSolutionStruct* lTS_ptr =
101 travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
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. " 110 STDAIR_LOG_DEBUG (lTS_ptr->describe());
113 stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
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());
123 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
125 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
126 == iExpectedPrice, oMessageExpectedPrice.str());
129 logOutputFile.close();
136 void testAllTravelCCMHelper (
const unsigned short iTestFlag) {
139 std::ostringstream oStr;
140 oStr <<
"TravelChoiceTestSuite_" << iTestFlag <<
".log";
141 const stdair::Filename_T lLogFilename (oStr.str());
144 std::ofstream logOutputFile;
146 logOutputFile.open (lLogFilename.c_str());
147 logOutputFile.clear();
150 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
154 travelccmService.buildSampleBom ();
157 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
160 const stdair::BookingRequestStruct& lBookingRequest =
161 travelccmService.buildSampleBookingRequest();
164 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
167 stdair::TravelSolutionList_T lTSList;
168 travelccmService.buildSampleTravelSolutions (lTSList);
171 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
172 STDAIR_LOG_DEBUG (lCSVDump);
175 const stdair::TravelSolutionStruct* lTS_HardRestriction_ptr =
176 travelccmService.chooseTravelSolution
177 (lTSList, lBookingRequest,
178 stdair::PassengerChoiceModel::HARD_RESTRICTION);
180 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Hard Restriction model: " 181 + lTS_HardRestriction_ptr->describe());
184 const stdair::TravelSolutionStruct* lTS_Price_Oriented_ptr =
185 travelccmService.chooseTravelSolution
186 (lTSList, lBookingRequest,
187 stdair::PassengerChoiceModel::PRICE_ORIENTED);
189 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Price Oriented model: " 190 + lTS_Price_Oriented_ptr->describe());
193 const stdair::TravelSolutionStruct* lTS_Hybrid_ptr =
194 travelccmService.chooseTravelSolution
195 (lTSList, lBookingRequest,
196 stdair::PassengerChoiceModel::HYBRID);
198 STDAIR_LOG_DEBUG (
"Chosen travel solution with the Hybrid model: " +
199 lTS_Hybrid_ptr->describe());
202 logOutputFile.close();
210 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
213 BOOST_AUTO_TEST_SUITE (master_test_suite)
218 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
224 const unsigned int lExpectedPrice = 1000;
226 BOOST_CHECK_NO_THROW (testTravelCCMHelper
228 stdair::PassengerChoiceModel::HARD_RESTRICTION,
235 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
241 const unsigned int lExpectedPrice = 900;
243 BOOST_CHECK_NO_THROW (testTravelCCMHelper
245 stdair::PassengerChoiceModel::PRICE_ORIENTED,
252 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
258 const unsigned int lExpectedPrice = 920;
260 BOOST_CHECK_NO_THROW (testTravelCCMHelper
262 stdair::PassengerChoiceModel::HYBRID,
269 BOOST_AUTO_TEST_CASE (all_models_test) {
271 BOOST_CHECK_NO_THROW (testAllTravelCCMHelper(3));
275 BOOST_AUTO_TEST_SUITE_END()