@@ -31,7 +31,7 @@ using namespace model;
31
31
32
32
class CTestFixture : public CModelTestFixtureBase {
33
33
protected:
34
- SModelParams::TStrDetectionRulePr
34
+ static SModelParams::TStrDetectionRulePr
35
35
makeScheduledEvent (const std::string& description, double start, double end) {
36
36
CRuleCondition conditionGte;
37
37
conditionGte.appliesTo (CRuleCondition::E_Time);
@@ -50,6 +50,13 @@ class CTestFixture : public CModelTestFixtureBase {
50
50
SModelParams::TStrDetectionRulePr event = std::make_pair (description, rule);
51
51
return event;
52
52
}
53
+
54
+ void makeModel (const SModelParams& params,
55
+ const model_t ::TFeatureVec& features,
56
+ core_t ::TTime startTime) {
57
+ this ->makeModelT <CCountingModelFactory>(
58
+ params, features, startTime, model_t ::E_Counting, m_Gatherer, m_Model);
59
+ }
53
60
};
54
61
55
62
BOOST_FIXTURE_TEST_CASE (testSkipSampling, CTestFixture) {
@@ -66,14 +73,11 @@ BOOST_FIXTURE_TEST_CASE(testSkipSampling, CTestFixture) {
66
73
67
74
// Model where gap is not skipped
68
75
{
69
- CModelFactory::SGathererInitializationData gathererNoGapInitData (startTime);
70
- CModelFactory::TDataGathererPtr gathererNoGap (
71
- factory.makeDataGatherer (gathererNoGapInitData));
72
- BOOST_REQUIRE_EQUAL (std::size_t (0 ), this ->addPerson (" p" , gathererNoGap));
73
- CModelFactory::SModelInitializationData modelNoGapInitData (gathererNoGap);
74
- CAnomalyDetectorModel::TModelPtr modelHolderNoGap (factory.makeModel (modelNoGapInitData));
75
- CCountingModel* modelNoGap =
76
- dynamic_cast <CCountingModel*>(modelHolderNoGap.get ());
76
+ CModelFactory::TDataGathererPtr gathererNoGap;
77
+ CModelFactory::TModelPtr modelNoGap;
78
+ this ->makeModelT <CCountingModelFactory>(
79
+ params, features, startTime, model_t ::E_Counting, gathererNoGap, modelNoGap);
80
+ BOOST_REQUIRE_EQUAL (0 , this ->addPerson (" p" , gathererNoGap));
77
81
78
82
// |2|2|0|0|1| -> 1.0 mean count
79
83
this ->addArrival (*gathererNoGap, 100 , " p" );
@@ -90,15 +94,12 @@ BOOST_FIXTURE_TEST_CASE(testSkipSampling, CTestFixture) {
90
94
91
95
// Model where gap is skipped
92
96
{
93
- CModelFactory::SGathererInitializationData gathererWithGapInitData (startTime);
94
- CModelFactory::TDataGathererPtr gathererWithGap (
95
- factory.makeDataGatherer (gathererWithGapInitData));
96
- BOOST_REQUIRE_EQUAL (std::size_t (0 ), this ->addPerson (" p" , gathererWithGap));
97
- CModelFactory::SModelInitializationData modelWithGapInitData (gathererWithGap);
98
- CAnomalyDetectorModel::TModelPtr modelHolderWithGap (
99
- factory.makeModel (modelWithGapInitData));
100
- CCountingModel* modelWithGap =
101
- dynamic_cast <CCountingModel*>(modelHolderWithGap.get ());
97
+ CModelFactory::TDataGathererPtr gathererWithGap;
98
+ CModelFactory::TModelPtr modelWithGap;
99
+ this ->makeModelT <CCountingModelFactory>(params, features, startTime,
100
+ model_t ::E_Counting,
101
+ gathererWithGap, modelWithGap);
102
+ BOOST_REQUIRE_EQUAL (0 , this ->addPerson (" p" , gathererWithGap));
102
103
103
104
// |2|2|0|0|1|
104
105
// |2|X|X|X|1| -> 1.5 mean count where X means skipped bucket
@@ -109,7 +110,7 @@ BOOST_FIXTURE_TEST_CASE(testSkipSampling, CTestFixture) {
109
110
this ->addArrival (*gathererWithGap, 280 , " p" );
110
111
modelWithGap->skipSampling (500 );
111
112
modelWithGap->prune (maxAgeBuckets);
112
- BOOST_REQUIRE_EQUAL (std::size_t ( 1 ) , gathererWithGap->numberActivePeople ());
113
+ BOOST_REQUIRE_EQUAL (1 , gathererWithGap->numberActivePeople ());
113
114
this ->addArrival (*gathererWithGap, 500 , " p" );
114
115
modelWithGap->sample (500 , 600 , m_ResourceMonitor);
115
116
@@ -137,14 +138,10 @@ BOOST_FIXTURE_TEST_CASE(testCheckScheduledEvents, CTestFixture) {
137
138
factory.features (features);
138
139
139
140
{
140
- CModelFactory::SGathererInitializationData gathererNoGapInitData (startTime);
141
- CModelFactory::TDataGathererPtr gatherer (factory.makeDataGatherer (gathererNoGapInitData));
142
- CModelFactory::SModelInitializationData modelNoGapInitData (gatherer);
143
- this ->addArrival (*gatherer, 200 , " p" );
144
-
145
- CAnomalyDetectorModel::TModelPtr modelHolderNoGap (factory.makeModel (modelNoGapInitData));
146
- CCountingModel* modelNoGap =
147
- dynamic_cast <CCountingModel*>(modelHolderNoGap.get ());
141
+ this ->makeModel (params, features, startTime);
142
+ CCountingModel* modelNoGap = dynamic_cast <CCountingModel*>(m_Model.get ());
143
+ BOOST_TEST_REQUIRE (modelNoGap);
144
+ BOOST_REQUIRE_EQUAL (0 , this ->addPerson (" p" , m_Gatherer));
148
145
149
146
SModelParams::TStrDetectionRulePrVec matchedEvents =
150
147
modelNoGap->checkScheduledEvents (50 );
@@ -186,14 +183,10 @@ BOOST_FIXTURE_TEST_CASE(testCheckScheduledEvents, CTestFixture) {
186
183
187
184
// Test sampleBucketStatistics
188
185
{
189
- CModelFactory::SGathererInitializationData gathererNoGapInitData (startTime);
190
- CModelFactory::TDataGathererPtr gatherer (factory.makeDataGatherer (gathererNoGapInitData));
191
- CModelFactory::SModelInitializationData modelNoGapInitData (gatherer);
192
- this ->addArrival (*gatherer, 100 , " p" );
193
-
194
- CAnomalyDetectorModel::TModelPtr modelHolderNoGap (factory.makeModel (modelNoGapInitData));
195
- CCountingModel* modelNoGap =
196
- dynamic_cast <CCountingModel*>(modelHolderNoGap.get ());
186
+ this ->makeModel (params, features, startTime);
187
+ CCountingModel* modelNoGap = dynamic_cast <CCountingModel*>(m_Model.get ());
188
+ BOOST_TEST_REQUIRE (modelNoGap);
189
+ BOOST_REQUIRE_EQUAL (0 , this ->addPerson (" p" , m_Gatherer));
197
190
198
191
// There are no events at this time
199
192
modelNoGap->sampleBucketStatistics (0 , 100 , m_ResourceMonitor);
@@ -226,18 +219,13 @@ BOOST_FIXTURE_TEST_CASE(testInterimBucketCorrector, CTestFixture) {
226
219
227
220
SModelParams params (bucketLength);
228
221
params.s_DecayRate = 0.001 ;
229
- auto interimBucketCorrector = std::make_shared<CInterimBucketCorrector>(bucketLength);
230
- CCountingModelFactory factory (params, interimBucketCorrector);
231
- model_t ::TFeatureVec features{model_t ::E_IndividualCountByBucketAndPerson};
232
- factory.features (features);
233
222
234
- CModelFactory::SGathererInitializationData gathererInitData (time );
235
- CModelFactory::TDataGathererPtr gatherer (factory.makeDataGatherer (gathererInitData));
236
- BOOST_REQUIRE_EQUAL (std::size_t (0 ), this ->addPerson (" p1" , gatherer));
237
- BOOST_REQUIRE_EQUAL (std::size_t (1 ), this ->addPerson (" p2" , gatherer));
238
- CModelFactory::SModelInitializationData modelInitData (gatherer);
239
- CAnomalyDetectorModel::TModelPtr modelHolder (factory.makeModel (modelInitData));
240
- CCountingModel* model{dynamic_cast <CCountingModel*>(modelHolder.get ())};
223
+ this ->makeModel (params, {model_t ::E_IndividualCountByBucketAndPerson}, time );
224
+ CCountingModel* model = dynamic_cast <CCountingModel*>(m_Model.get ());
225
+ BOOST_TEST_REQUIRE (model);
226
+
227
+ BOOST_REQUIRE_EQUAL (0 , this ->addPerson (" p1" , m_Gatherer));
228
+ BOOST_REQUIRE_EQUAL (1 , this ->addPerson (" p2" , m_Gatherer));
241
229
242
230
test::CRandomNumbers rng;
243
231
@@ -249,7 +237,7 @@ BOOST_FIXTURE_TEST_CASE(testInterimBucketCorrector, CTestFixture) {
249
237
std::sort (offsets.begin (), offsets.end ());
250
238
for (auto offset : offsets) {
251
239
rng.generateUniformSamples (0.0 , 1.0 , 1 , uniform01);
252
- this ->addArrival (*gatherer , time + static_cast <core_t ::TTime>(offset),
240
+ this ->addArrival (*m_Gatherer , time + static_cast <core_t ::TTime>(offset),
253
241
uniform01[0 ] < 0.5 ? " p1" : " p2" );
254
242
}
255
243
model->sample (time , time + bucketLength, m_ResourceMonitor);
@@ -260,11 +248,11 @@ BOOST_FIXTURE_TEST_CASE(testInterimBucketCorrector, CTestFixture) {
260
248
261
249
for (std::size_t i = 0u ; i < offsets.size (); ++i) {
262
250
rng.generateUniformSamples (0.0 , 1.0 , 1 , uniform01);
263
- this ->addArrival (*gatherer , time + static_cast <core_t ::TTime>(offsets[i]),
251
+ this ->addArrival (*m_Gatherer , time + static_cast <core_t ::TTime>(offsets[i]),
264
252
uniform01[0 ] < 0.5 ? " p1" : " p2" );
265
253
model->sampleBucketStatistics (time , time + bucketLength, m_ResourceMonitor);
266
254
BOOST_REQUIRE_EQUAL (static_cast <double >(i + 1 ) / 10.0 ,
267
- interimBucketCorrector ->completeness ());
255
+ m_InterimBucketCorrector ->completeness ());
268
256
}
269
257
}
270
258
0 commit comments