Skip to content

[ML] Factor out duplicated code in model library unit tests #1477

Open
@droberts195

Description

@droberts195

Many unit tests in the model library start off by creating a model, and there is a lot of duplicated code that does this, both within the suites for the different types of models and between the suites.

The affected files are:

CCountingModelTest.cc
CEventRateModelTest.cc
CEventRatePopulationModelTest.cc
CMetricModelTest.cc
CMetricPopulationModelTest.cc

For example there are:

  • Large blocks of code that call addArrival
  • Large blocks of type definitions
  • Free functions within the different test files that help with model setup
  • All these classes use a test fixture that has a protected resource monitor

There should be scope to refactor this to reduce duplication and verbosity. Some ideas are:

  • Create a separate file containing a test fixture base class that all the model tests can share (in Boost.Test a test fixture is a class that every unit test that uses it inherits from, so can use its protected methods and data as a code reuse mechanism)
  • Make some of the local setup helper functions methods of this base class so that they can be shared between the different suites of model tests
  • Move commonly used type definitions into this shared test fixture - then they will be available to every test without needing to be redefined within it
  • Add some methods that make it easier to add batches of arrivals
  • Modernise the code using initializer lists rather than batches of push_back calls
  • Add a test setup factory class to encapsulate some aspects of creating a model for unit testing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions