TravelCCM Logo  1.00.1
C++ Travel Customer Choice Model Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
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 
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 
128 
129 // /////////////// Main: Unit Test Suite //////////////
130 
131 // Set the UTF configuration (re-direct the output to a specific file)
132 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
133 
134 // Start the test suite
135 BOOST_AUTO_TEST_SUITE (master_test_suite)
136 
137 
140 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
141 
146  const unsigned int lExpectedPrice = 1000;
147 
148  BOOST_CHECK_NO_THROW (testTravelCCMHelper
149  (0,
150  stdair::PassengerChoiceModel::HARD_RESTRICTION,
151  lExpectedPrice));
152 }
153 
157 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
158 
163  const unsigned int lExpectedPrice = 900;
164 
165  BOOST_CHECK_NO_THROW (testTravelCCMHelper
166  (1,
167  stdair::PassengerChoiceModel::PRICE_ORIENTED,
168  lExpectedPrice));
169 }
170 
174 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
175 
180  const unsigned int lExpectedPrice = 920;
181 
182  BOOST_CHECK_NO_THROW (testTravelCCMHelper
183  (2,
184  stdair::PassengerChoiceModel::HYBRID,
185  lExpectedPrice));
186 }
187 
188 // End the test suite
189 BOOST_AUTO_TEST_SUITE_END()
190 
191