*/
#include <cassert>
#include <limits>
#include <sstream>
#include <fstream>
#include <string>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE OptimiseTestSuite
#include <boost/test/unit_test.hpp>
#include <stdair/basic/BasLogParams.hpp>
#include <stdair/basic/BasDBParams.hpp>
#include <stdair/service/Logger.hpp>
#include <rmol/config/rmol-paths.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("bomsforforecaster_utfresults.xml");
struct UnitTestConfig {
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
~UnitTestConfig() {
}
};
namespace RMOL {
struct BookingClassData {
double _bookingCount;
double _fare;
double _sellupFactor;
bool _censorshipFlag;
BookingClassData (const double iBookingCount, const double iFare,
const double iSellupFactor, const bool iCensorshipFlag)
: _bookingCount(iBookingCount), _fare(iFare),
_sellupFactor(iSellupFactor), _censorshipFlag(iCensorshipFlag) {
}
double getFare () const {
return _fare;
}
bool getCensorshipFlag () const {
return _censorshipFlag;
}
std::string toString() const {
std::ostringstream oStr;
oStr << std::endl
<< "[Booking class data information]" << std::endl
<< "Booking counter: " << _bookingCount << std::endl
<< "Fare: " << _fare << std::endl
<< "Sell-up Factor: " << _sellupFactor << std::endl
<< "censorshipFlag: " << _censorshipFlag << std::endl;
return oStr.str();
}
};
struct BookingClassDataSet {
typedef std::vector<BookingClassData*> BookingClassDataList_T;
int _numberOfClass;
double _minimumFare;
bool _censorshipFlag;
BookingClassDataList_T _bookingClassDataList;
BookingClassDataSet ()
: _numberOfClass(0), _minimumFare(0),
_censorshipFlag(false) {
}
void addBookingClassData (BookingClassData& ioBookingClassData) {
_bookingClassDataList.push_back (&ioBookingClassData);
}
stdair::NbOfClasses_T getNumberOfClass () const {
return _bookingClassDataList.size();
}
double getMinimumFare () const {
return _minimumFare;
}
bool getCensorshipFlag () const {
return _censorshipFlag;
}
void setMinimumFare (const double iMinFare) {
_minimumFare = iMinFare;
}
void setCensorshipFlag (const bool iCensorshipFlag) {
_censorshipFlag = iCensorshipFlag;
}
void updateMinimumFare() {
double minFare = std::numeric_limits<double>::max();
BookingClassDataList_T::iterator itBookingClassDataList;
for (itBookingClassDataList = _bookingClassDataList.begin();
itBookingClassDataList != _bookingClassDataList.end();
++itBookingClassDataList) {
BookingClassData* lBookingClassData = *itBookingClassDataList;
assert (lBookingClassData != NULL);
const double lFare = lBookingClassData->getFare();
if (lFare < minFare) {
minFare = lFare;
}
}
setMinimumFare(minFare);
}
void updateCensorshipFlag () {
bool censorshipFlag = false;
BookingClassDataList_T::iterator itBookingClassDataList;
for (itBookingClassDataList = _bookingClassDataList.begin();
itBookingClassDataList != _bookingClassDataList.end();
++itBookingClassDataList) {
BookingClassData* lBookingClassData = *itBookingClassDataList;
assert (lBookingClassData != NULL);
const bool lCensorshipFlagOfAClass =
lBookingClassData->getCensorshipFlag();
if (lCensorshipFlagOfAClass) {
censorshipFlag = true;
break;
}
}
setCensorshipFlag(censorshipFlag);
}
std::string toString() const {
std::ostringstream oStr;
oStr << std::endl
<< "[Booking class data set information]" << std::endl
<< "Number of classes: " << _numberOfClass << std::endl
<< "Minimum fare: " << _minimumFare << std::endl
<< "The data of the class set are sensored: " << _censorshipFlag
<< std::endl;
return oStr.str();
}
};
}
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (rmol_forecaster) {
std::string lLogFilename ("bomsforforecaster.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
rmolService.buildSampleBom();
RMOL::BookingClassDataSet lBookingClassDataSet;
RMOL::BookingClassData QClassData (10, 100, 1, false);
RMOL::BookingClassData MClassData (5, 150, 0.8, true);
RMOL::BookingClassData BClassData (0, 200, 0.6, false);
RMOL::BookingClassData YClassData (0, 300, 0.3, false);
STDAIR_LOG_DEBUG (QClassData.toString());
STDAIR_LOG_DEBUG (MClassData.toString());
STDAIR_LOG_DEBUG (BClassData.toString());
STDAIR_LOG_DEBUG (YClassData.toString());
lBookingClassDataSet.addBookingClassData (QClassData);
lBookingClassDataSet.addBookingClassData (MClassData);
lBookingClassDataSet.addBookingClassData (BClassData);
lBookingClassDataSet.addBookingClassData (YClassData);
STDAIR_LOG_DEBUG (lBookingClassDataSet.toString());
const stdair::NbOfClasses_T lNbOfClass = lBookingClassDataSet.getNumberOfClass();
STDAIR_LOG_DEBUG ("Number of Classes: " << lNbOfClass);
BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateMinimumFare());
const double lMinFare = lBookingClassDataSet.getMinimumFare();
STDAIR_LOG_DEBUG ("Minimum fare: " << lMinFare);
BOOST_CHECK_NO_THROW (lBookingClassDataSet.updateCensorshipFlag());
const bool lCensorshipFlag = lBookingClassDataSet.getCensorshipFlag();
STDAIR_LOG_DEBUG ("Censorship Flag: " << lCensorshipFlag);
logOutputFile.close();
}
BOOST_AUTO_TEST_SUITE_END()