14 #define BOOST_TEST_DYN_LINK
15 #define BOOST_TEST_MAIN
16 #define BOOST_TEST_MODULE DemandGenerationTest
17 #include <boost/test/unit_test.hpp>
19 #include <stdair/stdair_basic_types.hpp>
20 #include <stdair/basic/BasConst_General.hpp>
21 #include <stdair/basic/BasLogParams.hpp>
22 #include <stdair/basic/BasDBParams.hpp>
23 #include <stdair/basic/BasFileMgr.hpp>
24 #include <stdair/basic/ProgressStatusSet.hpp>
25 #include <stdair/bom/EventStruct.hpp>
26 #include <stdair/bom/EventQueue.hpp>
27 #include <stdair/bom/BookingRequestStruct.hpp>
28 #include <stdair/service/Logger.hpp>
34 namespace boost_utf = boost::unit_test;
37 std::ofstream utfReportStream (
"DemandGenerationTestSuite_utfresults.xml");
42 struct UnitTestConfig {
45 boost_utf::unit_test_log.set_stream (utfReportStream);
46 boost_utf::unit_test_log.set_format (boost_utf::XML);
47 boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
57 typedef std::pair<stdair::Count_T, stdair::Count_T> NbOfEventsPair_T;
58 typedef std::map<
const stdair::DemandStreamKeyStr_T,
59 NbOfEventsPair_T> NbOfEventsByDemandStreamMap_T;
65 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
68 BOOST_AUTO_TEST_SUITE (master_test_suite)
73 BOOST_AUTO_TEST_CASE (trademgen_simple_simulation_test) {
76 const stdair::RandomSeed_T lRandomSeed = stdair::DEFAULT_RANDOM_SEED;
82 const bool doesExistAndIsReadable =
83 stdair::BasFileMgr::doesExistAndIsReadable (lInputFilename);
84 BOOST_CHECK_MESSAGE (doesExistAndIsReadable ==
true,
85 "The '" << lInputFilename
86 <<
"' input file can not be open and read");
89 const stdair::Filename_T lLogFilename (
"DemandGenerationTestSuite.log");
92 std::ofstream logOutputFile;
94 logOutputFile.open (lLogFilename.c_str());
95 logOutputFile.clear();
98 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
102 BOOST_CHECK_NO_THROW (trademgenService.parseAndLoad (lInputFilename));
113 NbOfEventsByDemandStreamMap_T lNbOfEventsMap;
114 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
115 value_type (
"SIN-HND 2010-Feb-08 Y",
116 NbOfEventsPair_T (1, 10)));
117 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
118 value_type (
"SIN-HND 2010-Feb-09 Y",
119 NbOfEventsPair_T (1, 10)));
120 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
121 value_type (
"SIN-BKK 2010-Feb-08 Y",
122 NbOfEventsPair_T (1, 10)));
123 lNbOfEventsMap.insert (NbOfEventsByDemandStreamMap_T::
124 value_type (
"SIN-BKK 2010-Feb-09 Y",
125 NbOfEventsPair_T (1, 10)));
127 stdair::Count_T lRefExpectedNbOfEvents (40);
131 const stdair::Count_T& lExpectedNbOfEventsToBeGenerated =
132 trademgenService.getExpectedTotalNumberOfRequestsToBeGenerated();
134 BOOST_CHECK_EQUAL (lRefExpectedNbOfEvents,
135 std::floor (lExpectedNbOfEventsToBeGenerated));
137 BOOST_CHECK_MESSAGE (lRefExpectedNbOfEvents ==
138 std::floor (lExpectedNbOfEventsToBeGenerated),
139 "Expected total number of requests to be generated: "
140 << lExpectedNbOfEventsToBeGenerated
142 << std::floor (lExpectedNbOfEventsToBeGenerated)
143 <<
"). Reference value: " << lRefExpectedNbOfEvents);
146 stdair::DemandGenerationMethod lDemandGenerationMethod (stdair::DemandGenerationMethod::STA_ORD);
157 const stdair::Count_T& lActualNbOfEventsToBeGenerated =
158 trademgenService.generateFirstRequests(lDemandGenerationMethod);
161 STDAIR_LOG_DEBUG (
"Expected number of events: "
162 << lExpectedNbOfEventsToBeGenerated <<
", actual: "
163 << lActualNbOfEventsToBeGenerated);
166 const stdair::Count_T lRefActualNbOfEvents (40);
167 BOOST_CHECK_EQUAL (lRefActualNbOfEvents, lActualNbOfEventsToBeGenerated);
169 BOOST_CHECK_MESSAGE (lRefActualNbOfEvents == lActualNbOfEventsToBeGenerated,
170 "Actual total number of requests to be generated: "
171 << lExpectedNbOfEventsToBeGenerated
173 << std::floor (lExpectedNbOfEventsToBeGenerated)
174 <<
"). Reference value: " << lRefActualNbOfEvents);
177 const bool isQueueDone = trademgenService.isQueueDone();
178 BOOST_REQUIRE_MESSAGE (isQueueDone ==
false,
179 "The event queue should not be empty. You may check "
180 <<
"the input file: '" << lInputFilename <<
"'");
189 stdair::Count_T idx = 1;
190 while (trademgenService.isQueueDone() ==
false) {
193 stdair::EventStruct lEventStruct;
194 stdair::ProgressStatusSet lPPS = trademgenService.popEvent (lEventStruct);
197 STDAIR_LOG_DEBUG (
"Poped event: '" << lEventStruct.describe() <<
"'.");
200 const stdair::BookingRequestStruct& lPoppedRequest =
201 lEventStruct.getBookingRequest();
204 STDAIR_LOG_DEBUG (
"Poped booking request: '"
205 << lPoppedRequest.describe() <<
"'.");
208 const stdair::DemandGeneratorKey_T& lDemandStreamKey =
209 lPoppedRequest.getDemandGeneratorKey();
212 const NbOfEventsByDemandStreamMap_T::iterator itNbOfEventsMap =
213 lNbOfEventsMap.find (lDemandStreamKey);
214 BOOST_REQUIRE_MESSAGE (itNbOfEventsMap != lNbOfEventsMap.end(),
215 "The demand stream key '" << lDemandStreamKey
216 <<
"' is not expected in that test");
227 const NbOfEventsPair_T& lNbOfEventsPair = itNbOfEventsMap->second;
228 stdair::Count_T lCurrentNbOfEvents = lNbOfEventsPair.first;
229 const stdair::Count_T& lExpectedTotalNbOfEvents = lNbOfEventsPair.second;
232 const bool stillHavingRequestsToBeGenerated = trademgenService.
233 stillHavingRequestsToBeGenerated (lDemandStreamKey, lPPS,
234 lDemandGenerationMethod);
242 if (lCurrentNbOfEvents == 1) {
248 const stdair::ProgressStatus& lDemandStreamProgressStatus =
249 lPPS.getSpecificGeneratorStatus();
250 const stdair::Count_T& lNbOfRequests =
251 lDemandStreamProgressStatus.getExpectedNb();
253 BOOST_CHECK_EQUAL (lNbOfRequests, lExpectedTotalNbOfEvents);
254 BOOST_CHECK_MESSAGE (lNbOfRequests == lExpectedTotalNbOfEvents,
255 "[" << lDemandStreamKey
256 <<
"] Total number of requests to be generated: "
257 << lNbOfRequests <<
"). Expected value: "
258 << lExpectedTotalNbOfEvents);
262 STDAIR_LOG_DEBUG (
"=> [" << lDemandStreamKey <<
"][" << lCurrentNbOfEvents
263 <<
"/" << lExpectedTotalNbOfEvents
264 <<
"] is now processed. "
265 <<
"Still generate events for that demand stream? "
266 << stillHavingRequestsToBeGenerated);
270 if (stillHavingRequestsToBeGenerated ==
true) {
271 const stdair::BookingRequestPtr_T lNextRequest_ptr =
272 trademgenService.generateNextRequest (lDemandStreamKey,
273 lDemandGenerationMethod);
274 assert (lNextRequest_ptr != NULL);
281 const stdair::Duration_T lDuration =
282 lNextRequest_ptr->getRequestDateTime()
283 - lPoppedRequest.getRequestDateTime();
284 BOOST_REQUIRE_GT (lDuration.total_milliseconds(), 0);
285 BOOST_REQUIRE_MESSAGE (lDuration.total_milliseconds() > 0,
286 "[" << lDemandStreamKey
287 <<
"] The date-time of the generated event ("
288 << lNextRequest_ptr->getRequestDateTime()
289 <<
") is lower than the date-time "
290 <<
"of the current event ("
291 << lPoppedRequest.getRequestDateTime() <<
")");
294 STDAIR_LOG_DEBUG (
"[" << lDemandStreamKey <<
"][" << lCurrentNbOfEvents
295 <<
"/" << lExpectedTotalNbOfEvents
296 <<
"] Added request: '" << lNextRequest_ptr->describe()
297 <<
"'. Is queue done? "
298 << trademgenService.isQueueDone());
301 ++lCurrentNbOfEvents;
302 itNbOfEventsMap->second = NbOfEventsPair_T (lCurrentNbOfEvents,
303 lExpectedTotalNbOfEvents);
312 BOOST_CHECK_EQUAL (idx, lRefActualNbOfEvents);
313 BOOST_CHECK_MESSAGE (idx == lRefActualNbOfEvents,
314 "The total actual number of events is "
315 << lRefActualNbOfEvents <<
", but " << idx
316 <<
" events have been generated");
320 trademgenService.reset();
323 STDAIR_LOG_DEBUG (
"End of the simulation");
326 logOutputFile.close();
330 BOOST_AUTO_TEST_SUITE_END()