Skip to content

Commit

Permalink
[ML] Amalgamate addArrival methods in model tests (#1536)
Browse files Browse the repository at this point in the history
Provide a common interface to addArrival by extending the existing SMessage structure.

Relates to #1477
  • Loading branch information
edsavage authored Oct 15, 2020
1 parent 909adec commit 42b6be1
Show file tree
Hide file tree
Showing 7 changed files with 532 additions and 485 deletions.
30 changes: 16 additions & 14 deletions lib/model/unittest/CCountingModelTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ BOOST_FIXTURE_TEST_CASE(testSkipSampling, CTestFixture) {
BOOST_REQUIRE_EQUAL(0, this->addPerson("p", gathererNoGap));

// |2|2|0|0|1| -> 1.0 mean count
this->addArrival(*gathererNoGap, 100, "p");
this->addArrival(*gathererNoGap, 110, "p");
this->addArrival(SMessage(100, "p", TOptionalStr()), gathererNoGap);
this->addArrival(SMessage(110, "p", TOptionalStr()), gathererNoGap);
modelNoGap->sample(100, 200, m_ResourceMonitor);
this->addArrival(*gathererNoGap, 250, "p");
this->addArrival(*gathererNoGap, 280, "p");
this->addArrival(SMessage(250, "p", TOptionalStr()), gathererNoGap);
this->addArrival(SMessage(280, "p", TOptionalStr()), gathererNoGap);
modelNoGap->sample(200, 500, m_ResourceMonitor);
this->addArrival(*gathererNoGap, 500, "p");
this->addArrival(SMessage(500, "p", TOptionalStr()), gathererNoGap);
modelNoGap->sample(500, 600, m_ResourceMonitor);

BOOST_REQUIRE_EQUAL(1.0, *modelNoGap->baselineBucketCount(0));
Expand All @@ -103,15 +103,15 @@ BOOST_FIXTURE_TEST_CASE(testSkipSampling, CTestFixture) {

// |2|2|0|0|1|
// |2|X|X|X|1| -> 1.5 mean count where X means skipped bucket
this->addArrival(*gathererWithGap, 100, "p");
this->addArrival(*gathererWithGap, 110, "p");
this->addArrival(SMessage(100, "p", TOptionalStr()), gathererWithGap);
this->addArrival(SMessage(110, "p", TOptionalStr()), gathererWithGap);
modelWithGap->sample(100, 200, m_ResourceMonitor);
this->addArrival(*gathererWithGap, 250, "p");
this->addArrival(*gathererWithGap, 280, "p");
this->addArrival(SMessage(250, "p", TOptionalStr()), gathererWithGap);
this->addArrival(SMessage(280, "p", TOptionalStr()), gathererWithGap);
modelWithGap->skipSampling(500);
modelWithGap->prune(maxAgeBuckets);
BOOST_REQUIRE_EQUAL(1, gathererWithGap->numberActivePeople());
this->addArrival(*gathererWithGap, 500, "p");
this->addArrival(SMessage(500, "p", TOptionalStr()), gathererWithGap);
modelWithGap->sample(500, 600, m_ResourceMonitor);

BOOST_REQUIRE_EQUAL(1.5, *modelWithGap->baselineBucketCount(0));
Expand Down Expand Up @@ -237,8 +237,9 @@ BOOST_FIXTURE_TEST_CASE(testInterimBucketCorrector, CTestFixture) {
std::sort(offsets.begin(), offsets.end());
for (auto offset : offsets) {
rng.generateUniformSamples(0.0, 1.0, 1, uniform01);
this->addArrival(*m_Gatherer, time + static_cast<core_t::TTime>(offset),
uniform01[0] < 0.5 ? "p1" : "p2");
this->addArrival(SMessage(time + static_cast<core_t::TTime>(offset),
uniform01[0] < 0.5 ? "p1" : "p2", TOptionalStr()),
m_Gatherer);
}
model->sample(time, time + bucketLength, m_ResourceMonitor);
}
Expand All @@ -248,8 +249,9 @@ BOOST_FIXTURE_TEST_CASE(testInterimBucketCorrector, CTestFixture) {

for (std::size_t i = 0u; i < offsets.size(); ++i) {
rng.generateUniformSamples(0.0, 1.0, 1, uniform01);
this->addArrival(*m_Gatherer, time + static_cast<core_t::TTime>(offsets[i]),
uniform01[0] < 0.5 ? "p1" : "p2");
this->addArrival(SMessage(time + static_cast<core_t::TTime>(offsets[i]),
uniform01[0] < 0.5 ? "p1" : "p2", TOptionalStr()),
m_Gatherer);
model->sampleBucketStatistics(time, time + bucketLength, m_ResourceMonitor);
BOOST_REQUIRE_EQUAL(static_cast<double>(i + 1) / 10.0,
m_InterimBucketCorrector->completeness());
Expand Down
Loading

0 comments on commit 42b6be1

Please sign in to comment.