main_test_fixture.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_TESTS_MAIN_TEST_FIXTURE_HPP
15 #define MLPACK_TESTS_MAIN_TEST_FIXTURE_HPP
16 
17 #include <mlpack/core.hpp>
20 
32 #define BINDING_TEST_FIXTURE(CLASS_NAME) \
33  class CLASS_NAME : public MainTestFixture \
34  { \
35  public: \
36  CLASS_NAME() : MainTestFixture(IO::Parameters(STRINGIFY(BINDING_NAME))) \
37  { } \
38  };
39 
45 #define RUN_BINDING() BINDING_FUNCTION(params, timers)
46 
54 {
55  public:
57  MainTestFixture(const util::Params& paramsIn) :
58  paramsClean(paramsIn)
59  {
60  // For a test binding, the parameters will not have the correct maps in
61  // `functionMap`. This is because the test executable may also be adding
62  // options for different binding types (which happens in
63  // `cli_binding_test.cpp`, for instance). Therefore, we have to ensure that
64  // the right functions are in the function map, for every type that appears
65  // in any binding.
66  paramsClean.functionMap =
68 
70  }
71 
74  {
75  // Clean any allocated memory associated with any parameters.
76  CleanMemory();
77  }
78 
86  {
87  // Reset the parameters.
89 
90  // Reset the timers too...
91  timers.StopAllTimers();
92  timers.Reset();
93  }
94 
98  void CleanMemory()
99  {
101  }
102 
106  template<typename T>
107  void SetInputParam(const std::string& name, T&& value)
108  {
109  params.Get<typename std::remove_reference<T>::type>(name) =
110  std::forward<T>(value);
111  params.SetPassed(name);
112  }
113 
114  protected:
116  util::Params paramsClean;
118  util::Params params;
120  util::Timers timers;
121 };
122 
123 #endif
static const FunctionMapType & FunctionMap()
Get the populated function map.
util::Params params
Parameters object, which the binding will be called with.
void CleanMemory()
Clean any memory associated with the params object.
void ResetSettings()
Reset the params object to its initial state.
util::Params paramsClean
Untouched "clean" parameters object, used for resetting.
util::Timers timers
Timers object, which the binding will be called with.
void SetInputParam(const std::string &name, T &&value)
Set the input parameter name to have value value.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
MainTestFixture is a base class for Catch fixtures for mlpack binding tests.
void CleanMemory(util::Params &params)
Delete any unique pointers that are held by the IO object.
MainTestFixture(const util::Params &paramsIn)
Create a MainTestFixture with the given set of parameters.
~MainTestFixture()
Clean up any memory associated with the MainTestFixture.