$treeview $search $mathjax
00001 00005 // ////////////////////////////////////////////////////////////////////// 00006 // Import section 00007 // ////////////////////////////////////////////////////////////////////// 00008 // STL 00009 #include <sstream> 00010 #include <fstream> 00011 #include <string> 00012 #include <cmath> 00013 // Boost Unit Test Framework (UTF) 00014 #define BOOST_TEST_DYN_LINK 00015 #define BOOST_TEST_MAIN 00016 #define BOOST_TEST_MODULE CRSTestSuite 00017 #include <boost/test/unit_test.hpp> 00018 // StdAir 00019 #include <stdair/basic/BasLogParams.hpp> 00020 #include <stdair/basic/BasDBParams.hpp> 00021 #include <stdair/basic/BasFileMgr.hpp> 00022 #include <stdair/bom/TravelSolutionStruct.hpp> 00023 #include <stdair/bom/BookingRequestStruct.hpp> 00024 #include <stdair/service/Logger.hpp> 00025 // SimFQT 00026 #include <simfqt/SIMFQT_Types.hpp> 00027 // SimCRS 00028 #include <simcrs/SIMCRS_Service.hpp> 00029 #include <simcrs/config/simcrs-paths.hpp> 00030 00031 namespace boost_utf = boost::unit_test; 00032 00033 // (Boost) Unit Test XML Report 00034 std::ofstream utfReportStream ("CRSTestSuite_utfresults.xml"); 00035 00039 struct UnitTestConfig { 00041 UnitTestConfig() { 00042 boost_utf::unit_test_log.set_stream (utfReportStream); 00043 boost_utf::unit_test_log.set_format (boost_utf::XML); 00044 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units); 00045 //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests); 00046 } 00047 00049 ~UnitTestConfig() { 00050 } 00051 }; 00052 00053 // ////////////////////////////////////////////////////////////////////// 00057 const unsigned int testSimCRSHelper (const unsigned short iTestFlag, 00058 const stdair::Filename_T& iScheduleInputFilename, 00059 const stdair::Filename_T& iOnDInputFilename, 00060 const stdair::Filename_T& iFRAT5InputFilename, 00061 const stdair::Filename_T& iFFDisutilityInputFilename, 00062 const stdair::Filename_T& iYieldInputFilename, 00063 const stdair::Filename_T& iFareInputFilename, 00064 const bool isBuiltin, 00065 const unsigned int iExpectedNbOfTravelSolutions, 00066 const unsigned int iExpectedPrice) { 00067 00068 // CRS code 00069 const SIMCRS::CRSCode_T lCRSCode ("1P"); 00070 00071 // Output log File 00072 std::ostringstream oStr; 00073 oStr << "CRSTestSuite_" << iTestFlag << ".log"; 00074 const stdair::Filename_T lLogFilename (oStr.str()); 00075 00076 // Set the log parameters 00077 std::ofstream logOutputFile; 00078 // Open and clean the log outputfile 00079 logOutputFile.open (lLogFilename.c_str()); 00080 logOutputFile.clear(); 00081 00082 // Initialise the list of classes/buckets 00083 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); 00084 SIMCRS::SIMCRS_Service simcrsService (lLogParams, lCRSCode); 00085 00086 stdair::Date_T lPreferredDepartureDate;; 00087 stdair::Date_T lRequestDate; 00088 stdair::TripType_T lTripType; 00089 00090 // Check wether or not a (CSV) input file should be read 00091 if (isBuiltin == true) { 00092 00093 // Build the default sample BOM tree 00094 simcrsService.buildSampleBom(); 00095 00096 lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08"); 00097 lRequestDate = boost::gregorian::from_string ("2010/01/21"); 00098 lTripType = "OW"; 00099 00100 } else { 00101 00102 // Build the BOM tree from parsing input files 00103 stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename); 00104 stdair::ODFilePath lODFilePath (iOnDInputFilename); 00105 stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename); 00106 stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename); 00107 const SIMFQT::FareFilePath lFareFilePath (iFareInputFilename); 00108 const AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename); 00109 simcrsService.parseAndLoad (lScheduleFilePath, lODFilePath, 00110 lFRAT5FilePath, lFFDisutilityFilePath, 00111 lYieldFilePath, lFareFilePath); 00112 00113 lPreferredDepartureDate = boost::gregorian::from_string ("2011/01/31"); 00114 lRequestDate = boost::gregorian::from_string ("2011/01/22"); 00115 lTripType = "RI"; 00116 } 00117 00118 // Create an empty booking request structure 00119 const stdair::AirportCode_T lOrigin ("SIN"); 00120 const stdair::AirportCode_T lDestination ("BKK"); 00121 const stdair::AirportCode_T lPOS ("SIN"); 00122 const stdair::Duration_T lRequestTime (boost::posix_time::hours(10)); 00123 const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime); 00124 const stdair::CabinCode_T lPreferredCabin ("Eco"); 00125 const stdair::PartySize_T lPartySize (3); 00126 const stdair::ChannelLabel_T lChannel ("IN"); 00127 const stdair::DayDuration_T lStayDuration (7); 00128 const stdair::FrequentFlyer_T lFrequentFlyerType ("M"); 00129 const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10)); 00130 const stdair::WTP_T lWTP (1000.0); 00131 const stdair::PriceValue_T lValueOfTime (100.0); 00132 const stdair::ChangeFees_T lChangeFees (true); 00133 const stdair::Disutility_T lChangeFeeDisutility (50); 00134 const stdair::NonRefundable_T lNonRefundable (true); 00135 const stdair::Disutility_T lNonRefundableDisutility (50); 00136 const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination, 00137 lPOS, 00138 lPreferredDepartureDate, 00139 lRequestDateTime, 00140 lPreferredCabin, 00141 lPartySize, lChannel, 00142 lTripType, lStayDuration, 00143 lFrequentFlyerType, 00144 lPreferredDepartureTime, 00145 lWTP, lValueOfTime, 00146 lChangeFees, 00147 lChangeFeeDisutility, 00148 lNonRefundable, 00149 lNonRefundableDisutility); 00150 stdair::TravelSolutionList_T lTravelSolutionList = 00151 simcrsService.calculateSegmentPathList (lBookingRequest); 00152 00153 // Price the travel solution 00154 simcrsService.fareQuote (lBookingRequest, lTravelSolutionList); 00155 00156 // 00157 const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size(); 00158 00159 // DEBUG 00160 std::ostringstream oMessageKeptTS; 00161 oMessageKeptTS << "The number of travel solutions for the booking request '" 00162 << lBookingRequest.describe() << "' is actually " 00163 << lNbOfTravelSolutions << ". That number is expected to be " 00164 << iExpectedNbOfTravelSolutions << "."; 00165 STDAIR_LOG_DEBUG (oMessageKeptTS.str()); 00166 00167 BOOST_CHECK_EQUAL (lNbOfTravelSolutions, iExpectedNbOfTravelSolutions); 00168 00169 BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == iExpectedNbOfTravelSolutions, 00170 oMessageKeptTS.str()); 00171 00176 stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front(); 00177 00182 const stdair::FareOptionList_T& lFareOptionList = 00183 lTravelSolution.getFareOptionList(); 00184 00193 stdair::FareOptionStruct lFareOption = lFareOptionList.front(); 00194 lTravelSolution.setChosenFareOption (lFareOption); 00195 00196 // DEBUG 00197 std::ostringstream oMessageKeptFare; 00198 oMessageKeptFare 00199 << "The price given by the fare quoter for the booking request: '" 00200 << lBookingRequest.describe() << "' and travel solution: '" 00201 << lTravelSolution.describe() << "' is actually " << lFareOption.getFare() 00202 << " Euros. It is expected to be " << iExpectedPrice << " Euros."; 00203 STDAIR_LOG_DEBUG (oMessageKeptFare.str()); 00204 00205 BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice); 00206 00207 BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5) 00208 == iExpectedPrice, oMessageKeptFare.str()); 00209 00217 // DEBUG 00218 STDAIR_LOG_DEBUG ("A booking will now (attempted to) be made on the " 00219 "travel solution '" << lTravelSolution.describe() 00220 << "', for a party size of " << lPartySize << "."); 00221 00222 const bool isSellSuccessful = 00223 simcrsService.sell (lTravelSolution, lPartySize); 00224 00225 // Close the log file 00226 logOutputFile.close(); 00227 00228 return isSellSuccessful; 00229 00230 } 00231 00232 00233 // /////////////// Main: Unit Test Suite ////////////// 00234 00235 // Set the UTF configuration (re-direct the output to a specific file) 00236 BOOST_GLOBAL_FIXTURE (UnitTestConfig); 00237 00238 // Start the test suite 00239 BOOST_AUTO_TEST_SUITE (master_test_suite) 00240 00241 00244 BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) { 00245 00246 // Schedule input filename 00247 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR 00248 "/rds01/schedule.csv"); 00249 00250 // O&D input filename 00251 const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/ond01.csv"); 00252 00253 // FRAT5 curve input file name 00254 const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR 00255 "/frat5.csv"); 00256 00257 // Fare family disutility curve input file name 00258 const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR 00259 "/ffDisutility.csv"); 00260 00261 // Yield input filename 00262 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR 00263 "/rds01/yield.csv"); 00264 00265 // Fare input filename 00266 const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR 00267 "/rds01/fare.csv"); 00268 00269 // State whether the BOM tree should be built-in or parsed from input files 00270 const bool isBuiltin = false; 00271 00277 const unsigned int lExpectedPrice = 400; 00278 const unsigned int lExpectedNbOfTravelSolutions = 1; 00279 00280 bool isSellSuccessful = false; 00281 00282 BOOST_CHECK_NO_THROW (isSellSuccessful = 00283 testSimCRSHelper (0, 00284 lScheduleInputFilename, 00285 lOnDInputFilename, 00286 lFRAT5InputFilename, 00287 lFFDisutilityInputFilename, 00288 lYieldInputFilename, 00289 lFareInputFilename, 00290 isBuiltin, 00291 lExpectedNbOfTravelSolutions, 00292 lExpectedPrice)); 00293 00294 // DEBUG 00295 std::ostringstream oMessageSell; 00296 const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No"; 00297 oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr; 00298 STDAIR_LOG_DEBUG (oMessageSell.str()); 00299 00300 BOOST_CHECK_EQUAL (isSellSuccessful, true); 00301 00302 BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str()); 00303 00304 00305 } 00306 00307 00311 BOOST_AUTO_TEST_CASE (simcrs_simple_default_bom_simulation_test) { 00312 00313 // State whether the BOM tree should be built-in or parsed from input files 00314 const bool isBuiltin = true; 00315 00321 const unsigned int lExpectedPrice = 900; 00322 const unsigned int lExpectedNbOfTravelSolutions = 1; 00323 00324 bool isSellSuccessful = false; 00325 00326 BOOST_CHECK_NO_THROW (isSellSuccessful = 00327 testSimCRSHelper (1, 00328 " ", " ", " ", " ", " ", " ", 00329 isBuiltin, 00330 lExpectedNbOfTravelSolutions, 00331 lExpectedPrice)); 00332 00333 // DEBUG 00334 std::ostringstream oMessageSell; 00335 const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No"; 00336 oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr; 00337 STDAIR_LOG_DEBUG (oMessageSell.str()); 00338 00339 BOOST_CHECK_EQUAL (isSellSuccessful, true); 00340 00341 BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str()); 00342 00343 00344 } 00345 00346 // End the test suite 00347 BOOST_AUTO_TEST_SUITE_END() 00348 00349