29 lines
1.1 KiB
C++
29 lines
1.1 KiB
C++
|
|
#include "test_harness.h"
|
||
|
|
#include <TestProject/RNG/model/CompositeModel.h>
|
||
|
|
#include <TestProject/RNG/model/ConstantModel.h>
|
||
|
|
#include <TestProject/RNG/model/LinearModel.h>
|
||
|
|
using json = nlohmann::json;
|
||
|
|
|
||
|
|
TEST(composite_sums_base_and_noise) {
|
||
|
|
auto base = std::make_unique<ConstantModel>(json::object(), 50.0f);
|
||
|
|
auto noise = std::make_unique<LinearModel>(json{{"k", 2.0f}}, 0.0f);
|
||
|
|
CompositeModel m(std::move(base), std::move(noise));
|
||
|
|
CHECK_FLOAT_EQ(m.evaluate(0), 50.0f, 0.001f);
|
||
|
|
CHECK_FLOAT_EQ(m.evaluate(5), 60.0f, 0.001f);
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(composite_both_constant) {
|
||
|
|
auto base = std::make_unique<ConstantModel>(json::object(), 10.0f);
|
||
|
|
auto noise = std::make_unique<ConstantModel>(json::object(), 3.0f);
|
||
|
|
CompositeModel m(std::move(base), std::move(noise));
|
||
|
|
CHECK_FLOAT_EQ(m.evaluate(0), 13.0f, 0.001f);
|
||
|
|
CHECK_FLOAT_EQ(m.evaluate(999), 13.0f, 0.001f);
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(composite_evaluateBool_returns_false) {
|
||
|
|
auto base = std::make_unique<ConstantModel>(json::object(), 1.0f);
|
||
|
|
auto noise = std::make_unique<ConstantModel>(json::object(), 2.0f);
|
||
|
|
CompositeModel m(std::move(base), std::move(noise));
|
||
|
|
CHECK_EQ(m.evaluateBool(0), false);
|
||
|
|
}
|