$treeview $search $mathjax
TravelCCM Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

TravelChoiceTestSuite.cpp

Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012 // Boost Unit Test Framework (UTF)
00013 #define BOOST_TEST_DYN_LINK
00014 #define BOOST_TEST_MAIN
00015 #define BOOST_TEST_MODULE TravelCCMTest
00016 #include <boost/test/unit_test.hpp>
00017 // StdAir
00018 #include <stdair/basic/BasLogParams.hpp>
00019 #include <stdair/basic/BasDBParams.hpp>
00020 #include <stdair/basic/BasFileMgr.hpp>
00021 #include <stdair/basic/PassengerChoiceModel.hpp>
00022 #include <stdair/bom/TravelSolutionStruct.hpp>
00023 #include <stdair/bom/BookingRequestStruct.hpp>
00024 #include <stdair/service/Logger.hpp>
00025 // TravelCCM
00026 #include <travelccm/TRAVELCCM_Service.hpp>
00027 #include <travelccm/config/travelccm-paths.hpp>
00028 
00029 namespace boost_utf = boost::unit_test;
00030 
00031 // (Boost) Unit Test XML Report
00032 std::ofstream utfReportStream ("TravelChoiceTestSuite_utfresults.xml");
00033 
00037 struct UnitTestConfig {
00039   UnitTestConfig() {
00040     boost_utf::unit_test_log.set_stream (utfReportStream);
00041     boost_utf::unit_test_log.set_format (boost_utf::XML);
00042     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00043     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00044   }
00046   ~UnitTestConfig() {
00047   }
00048 };
00049 
00050 // //////////////////////////////////////////////////////////////////////
00054 void testTravelCCMHelper (const unsigned short iTestFlag,
00055                           const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
00056                           const unsigned int iExpectedPrice) {
00057 
00058   // Output log File
00059   std::ostringstream oStr;
00060   oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log";
00061   const stdair::Filename_T lLogFilename (oStr.str());
00062     
00063   // Set the log parameters
00064   std::ofstream logOutputFile;
00065   // Open and clean the log outputfile
00066   logOutputFile.open (lLogFilename.c_str());
00067   logOutputFile.clear();
00068   
00069   // Initialise the service context
00070   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00071   
00072   // Build the BOM tree
00073   TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
00074   travelccmService.buildSampleBom ();
00075 
00076   // DEBUG
00077   STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
00078 
00079   // Build a list of travel solutions
00080   const stdair::BookingRequestStruct& lBookingRequest =
00081     travelccmService.buildSampleBookingRequest();
00082 
00083   // DEBUG
00084   STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
00085 
00086   // Build the sample BOM tree
00087   stdair::TravelSolutionList_T lTSList;
00088   travelccmService.buildSampleTravelSolutions (lTSList);
00089 
00090   // DEBUG: Display the list of travel solutions
00091   const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
00092   STDAIR_LOG_DEBUG (lCSVDump);
00093   
00094   // Choose a travel solution
00095   const stdair::TravelSolutionStruct* lTS_ptr =
00096     travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
00097 
00098   // Check that a solution has been found
00099   BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
00100                          "No travel solution can be found for "
00101                          << lBookingRequest.display()
00102                          << " within the following list of travel solutions. "
00103                          << lCSVDump);
00104 
00105   STDAIR_LOG_DEBUG (lTS_ptr->describe());
00106 
00107   // Retrieve the chosen fare option
00108   stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
00109 
00110   // DEBUG
00111   std::ostringstream oMessageExpectedPrice;
00112   oMessageExpectedPrice << "The price chosen by the passenger is: "
00113                         << lFareOption.getFare() << " Euros. It is expected to be "
00114                         << iExpectedPrice << " Euros.";
00115   STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());
00116 
00117   // Check that the price corresponds to the expected one
00118   BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
00119 
00120   BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
00121                        == iExpectedPrice, oMessageExpectedPrice.str());
00122 
00123   // Close the log file
00124   logOutputFile.close();
00125 
00126 }
00127 
00131 void testAllTravelCCMHelper (const unsigned short iTestFlag) {
00132 
00133   // Output log File
00134   std::ostringstream oStr;
00135   oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log";
00136   const stdair::Filename_T lLogFilename (oStr.str());
00137     
00138   // Set the log parameters
00139   std::ofstream logOutputFile;
00140   // Open and clean the log outputfile
00141   logOutputFile.open (lLogFilename.c_str());
00142   logOutputFile.clear();
00143   
00144   // Initialise the service context
00145   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00146   
00147   // Build the BOM tree
00148   TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
00149   travelccmService.buildSampleBom ();
00150 
00151   // DEBUG
00152   STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
00153 
00154   // Build a list of travel solutions
00155   const stdair::BookingRequestStruct& lBookingRequest =
00156     travelccmService.buildSampleBookingRequest();
00157 
00158   // DEBUG
00159   STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
00160 
00161   // Build the sample BOM tree
00162   stdair::TravelSolutionList_T lTSList;
00163   travelccmService.buildSampleTravelSolutions (lTSList);
00164 
00165   // DEBUG: Display the list of travel solutions
00166   const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
00167   STDAIR_LOG_DEBUG (lCSVDump);
00168   
00169   // Choose a travel solution with the hard restriction method.
00170   const stdair::TravelSolutionStruct* lTS_HardRestriction_ptr =
00171     travelccmService.chooseTravelSolution 
00172     (lTSList, lBookingRequest, 
00173      stdair::PassengerChoiceModel::HARD_RESTRICTION); 
00174   
00175   STDAIR_LOG_DEBUG ("Chosen travel solution with the Hard Restriction model: "
00176                     + lTS_HardRestriction_ptr->describe()); 
00177 
00178   // Choose a travel solution with the price oriented model
00179   const stdair::TravelSolutionStruct* lTS_Price_Oriented_ptr =
00180     travelccmService.chooseTravelSolution 
00181     (lTSList, lBookingRequest, 
00182      stdair::PassengerChoiceModel::PRICE_ORIENTED); 
00183  
00184   STDAIR_LOG_DEBUG ("Chosen travel solution with the Price Oriented model: " 
00185                     + lTS_Price_Oriented_ptr->describe());
00186 
00187   // Choose a travel solution with the hybrid model
00188   const stdair::TravelSolutionStruct* lTS_Hybrid_ptr =
00189     travelccmService.chooseTravelSolution 
00190     (lTSList, lBookingRequest, 
00191      stdair::PassengerChoiceModel::HYBRID); 
00192  
00193   STDAIR_LOG_DEBUG ("Chosen travel solution with the Hybrid model: " +
00194                     lTS_Hybrid_ptr->describe());
00195 
00196   // Close the log file
00197   logOutputFile.close();
00198 
00199 }
00200 
00201 
00202 // /////////////// Main: Unit Test Suite //////////////
00203 
00204 // Set the UTF configuration (re-direct the output to a specific file)
00205 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00206 
00207 // Start the test suite
00208 BOOST_AUTO_TEST_SUITE (master_test_suite)
00209 
00210 
00213 BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
00214 
00219   const unsigned int lExpectedPrice = 1000;
00220   
00221   BOOST_CHECK_NO_THROW (testTravelCCMHelper
00222                         (0,
00223                          stdair::PassengerChoiceModel::HARD_RESTRICTION,
00224                          lExpectedPrice));
00225 }
00226 
00230 BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
00231 
00236   const unsigned int lExpectedPrice = 900;
00237   
00238   BOOST_CHECK_NO_THROW (testTravelCCMHelper
00239                         (1,
00240                          stdair::PassengerChoiceModel::PRICE_ORIENTED,
00241                          lExpectedPrice));
00242 }
00243 
00247 BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
00248 
00253   const unsigned int lExpectedPrice = 920;
00254   
00255   BOOST_CHECK_NO_THROW (testTravelCCMHelper
00256                         (2,
00257                          stdair::PassengerChoiceModel::HYBRID,
00258                          lExpectedPrice));
00259 }
00260 
00264 BOOST_AUTO_TEST_CASE (all_models_test) {
00265 
00266   BOOST_CHECK_NO_THROW (testAllTravelCCMHelper(3));
00267 }
00268 
00269 // End the test suite
00270 BOOST_AUTO_TEST_SUITE_END()
00271 
00272