15 #define BOOST_TEST_DYN_LINK
16 #define BOOST_TEST_MAIN
17 #define BOOST_TEST_MODULE OptimiseTestSuite
18 #include <boost/test/unit_test.hpp>
20 #include <stdair/basic/BasLogParams.hpp>
21 #include <stdair/basic/BasDBParams.hpp>
22 #include <stdair/service/Logger.hpp>
25 #include <rmol/config/rmol-paths.hpp>
27 namespace boost_utf = boost::unit_test;
30 std::ofstream utfReportStream (
"bomsforforecaster_utfresults.xml");
35 struct UnitTestConfig {
38 boost_utf::unit_test_log.set_stream (utfReportStream);
39 boost_utf::unit_test_log.set_format (boost_utf::XML);
40 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
52 struct BookingClassData {
61 BookingClassData (
const double iBookingCount,
const double iFare,
62 const double iSellupFactor,
const bool iCensorshipFlag)
63 : _bookingCount(iBookingCount), _fare(iFare),
64 _sellupFactor(iSellupFactor), _censorshipFlag(iCensorshipFlag) {
68 double getFare ()
const {
72 bool getCensorshipFlag ()
const {
73 return _censorshipFlag;
77 std::string toString()
const {
78 std::ostringstream oStr;
80 <<
"[Booking class data information]" << std::endl
81 <<
"Booking counter: " << _bookingCount << std::endl
82 <<
"Fare: " << _fare << std::endl
83 <<
"Sell-up Factor: " << _sellupFactor << std::endl
84 <<
"censorshipFlag: " << _censorshipFlag << std::endl;
91 struct BookingClassDataSet {
93 typedef std::vector<BookingClassData*> BookingClassDataList_T;
99 BookingClassDataList_T _bookingClassDataList;
102 BookingClassDataSet ()
103 : _numberOfClass(0), _minimumFare(0),
104 _censorshipFlag(false) {
108 void addBookingClassData (BookingClassData& ioBookingClassData) {
109 _bookingClassDataList.push_back (&ioBookingClassData);
113 stdair::NbOfClasses_T getNumberOfClass ()
const {
114 return _bookingClassDataList.size();
117 double getMinimumFare ()
const {
121 bool getCensorshipFlag ()
const {
122 return _censorshipFlag;
126 void setMinimumFare (
const double iMinFare) {
127 _minimumFare = iMinFare;
130 void setCensorshipFlag (
const bool iCensorshipFlag) {
131 _censorshipFlag = iCensorshipFlag;
135 void updateMinimumFare() {
136 double minFare = std::numeric_limits<double>::max();
137 BookingClassDataList_T::iterator itBookingClassDataList;
138 for (itBookingClassDataList = _bookingClassDataList.begin();
139 itBookingClassDataList != _bookingClassDataList.end();
140 ++itBookingClassDataList) {
141 BookingClassData* lBookingClassData = *itBookingClassDataList;
142 assert (lBookingClassData != NULL);
144 const double lFare = lBookingClassData->getFare();
145 if (lFare < minFare) {
150 setMinimumFare(minFare);
154 void updateCensorshipFlag () {
155 bool censorshipFlag =
false;
156 BookingClassDataList_T::iterator itBookingClassDataList;
157 for (itBookingClassDataList = _bookingClassDataList.begin();
158 itBookingClassDataList != _bookingClassDataList.end();
159 ++itBookingClassDataList) {
160 BookingClassData* lBookingClassData = *itBookingClassDataList;
161 assert (lBookingClassData != NULL);
163 const bool lCensorshipFlagOfAClass =
164 lBookingClassData->getCensorshipFlag();
165 if (lCensorshipFlagOfAClass) {
166 censorshipFlag =
true;
171 setCensorshipFlag(censorshipFlag);
175 std::string toString()
const {
176 std::ostringstream oStr;
178 <<
"[Booking class data set information]" << std::endl
179 <<
"Number of classes: " << _numberOfClass << std::endl
180 <<
"Minimum fare: " << _minimumFare << std::endl
181 <<
"The data of the class set are sensored: " << _censorshipFlag
220 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
225 BOOST_AUTO_TEST_SUITE (master_test_suite)
230 BOOST_AUTO_TEST_CASE (rmol_forecaster) {
233 std::string lLogFilename (
"bomsforforecaster.log");
234 std::ofstream logOutputFile;
237 logOutputFile.open (lLogFilename.c_str());
238 logOutputFile.clear();
241 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
247 rmolService.buildSampleBom();
250 RMOL::BookingClassDataSet lBookingClassDataSet;
253 RMOL::BookingClassData QClassData (10, 100, 1,
false);
254 RMOL::BookingClassData MClassData (5, 150, 0.8,
true);
255 RMOL::BookingClassData BClassData (0, 200, 0.6,
false);
256 RMOL::BookingClassData YClassData (0, 300, 0.3,
false);
259 STDAIR_LOG_DEBUG (QClassData.toString());
260 STDAIR_LOG_DEBUG (MClassData.toString());
261 STDAIR_LOG_DEBUG (BClassData.toString());
262 STDAIR_LOG_DEBUG (YClassData.toString());
265 lBookingClassDataSet.addBookingClassData (QClassData);
266 lBookingClassDataSet.addBookingClassData (MClassData);
267 lBookingClassDataSet.addBookingClassData (BClassData);
268 lBookingClassDataSet.addBookingClassData (YClassData);
271 STDAIR_LOG_DEBUG (lBookingClassDataSet.toString());
274 const stdair::NbOfClasses_T lNbOfClass = lBookingClassDataSet.getNumberOfClass();
277 STDAIR_LOG_DEBUG (
"Number of Classes: " << lNbOfClass);
280 BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateMinimumFare());
281 const double lMinFare = lBookingClassDataSet.getMinimumFare();
284 STDAIR_LOG_DEBUG (
"Minimum fare: " << lMinFare);
287 BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateCensorshipFlag());
288 const bool lCensorshipFlag = lBookingClassDataSet.getCensorshipFlag();
291 STDAIR_LOG_DEBUG (
"Censorship Flag: " << lCensorshipFlag);
294 logOutputFile.close();
298 BOOST_AUTO_TEST_SUITE_END()