Skip to content

Conversation

@edsavage
Copy link
Contributor

@edsavage edsavage commented Oct 2, 2020

Move existing model test helper functions to base class and share functionality where possible.

While this goes some way to reducing code duplication there may still be scope to

  • generalise the existing helper functions further to reduce their number
  • add further helper functions to encapsulate code duplicated in multiple suites

Relates to #1477

Move existing model test helper functions to base class and share functionality where possible.

namespace {

const std::string EMPTY_STRING;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in an unnamed namespace in several of the files. Could it be made a public or protected static constant on the test fixture? Then it would still be usable in the tests without qualification, but wouldn't be duplicated.

Copy link
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I made a few minor comments and also wonder if we can pull one more bit of functionality up to the base class.

CEventData makeEventData(core_t::TTime time,
std::size_t pid,
double value,
const TOptionalStr& influence = TOptionalStr()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible to move this into the base class. We have makeEventData in CEventRateModelTest which I think this could be combined with.

<< ml::core::CContainerPrinter::print(orderedAnomalies));
}

void CModelTestFixtureBase::generateAndCompareKey(const ml::model::function_t::TFunctionVec& countFunctions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be static.


int detectorIndex{0};
for (const auto& countFunction : countFunctions) {
for (bool usingNull : useNull) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just moved here, but this can be more concise:

Suggested change
for (bool usingNull : useNull) {
for (bool usingNull : {true, false}) {

then delete useNull. Similar for others below.

for (std::size_t i = 0u; i < values.size(); ++i) {
processBucket(time, bucketLength, values[i], influencers[i], *gatherer,
m_ResourceMonitor, model, annotatedProbability);
processBucket(time, bucketLength, values[i], influencers[i],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency it feels like all the calls to processBucket should be qualified (it's our usual style and you've done it for the other methods you've added):

Suggested change
processBucket(time, bucketLength, values[i], influencers[i],
this->processBucket(time, bucketLength, values[i], influencers[i],

Copy link
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@edsavage edsavage merged commit 499338d into elastic:master Oct 6, 2020
edsavage added a commit to edsavage/ml-cpp that referenced this pull request Oct 6, 2020
Move existing model test helper functions to base class and share functionality where possible.
edsavage added a commit that referenced this pull request Oct 6, 2020
Move existing model test helper functions to base class and share functionality where possible.

Backports #1523
@edsavage edsavage deleted the refactor_model_test_helper_functions branch October 6, 2020 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants