11 #ifndef TEST_INTERFACE_MODEL_H_
12 #define TEST_INTERFACE_MODEL_H_
20 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
22 #include <boost/noncopyable.hpp>
24 #include "eckit/config/LocalConfiguration.h"
25 #include "eckit/testing/Test.h"
33 #include "oops/util/DateTime.h"
34 #include "oops/util/Duration.h"
41 template <
typename MODEL>
class ModelFixture :
private boost::noncopyable {
64 return theModelFixture;
83 ~ModelFixture<MODEL>() {}
85 std::unique_ptr<const eckit::LocalConfiguration>
test_;
86 std::unique_ptr<const Geometry_>
resol_;
87 std::unique_ptr<const State_>
xref_;
88 std::unique_ptr<const ModelAux_>
bias_;
89 std::unique_ptr<const Model_>
model_;
97 const util::Duration zero(0);
98 EXPECT(Test_::model().timeResolution() > zero);
107 const double ininorm = Test_::xref().
norm();
108 State_ xx(Test_::xref());
109 const util::DateTime vt(xx.validTime());
111 const util::Duration zero(0);
114 Test_::model().forecast(xx, Test_::bias(), zero, post);
116 EXPECT(xx.validTime() == vt);
117 EXPECT(xx.norm() == ininorm);
120 EXPECT(Test_::xref().norm() == ininorm);
129 const double fnorm = Test_::test().getDouble(
"final norm");
130 const double tol = Test_::test().getDouble(
"tolerance");
131 const util::Duration len(Test_::test().getString(
"forecast length"));
133 const double ininorm = Test_::xref().norm();
134 State_ xx(Test_::xref());
135 const util::DateTime vt(xx.validTime()+len);
139 Test_::model().forecast(xx, Test_::bias(), len, post);
141 EXPECT(xx.validTime() == vt);
143 oops::Log::debug() <<
"xx.norm(): " << std::fixed << std::setprecision(8) << xx.norm()
145 oops::Log::debug() <<
"fnorm: " << std::fixed << std::setprecision(8) << fnorm << std::endl;
147 EXPECT(oops::is_close(xx.norm(), fnorm, tol));
150 EXPECT(Test_::xref().norm() == ininorm);
159 const bool testreforecast = Test_::test().getBool(
"test reforecast",
true);
161 if (testreforecast) {
163 const util::Duration len(Test_::test().getString(
"forecast length"));
165 const double ininorm = Test_::xref().norm();
168 State_ xx1(Test_::xref());
169 State_ xx2(Test_::xref());
172 const util::DateTime vt(xx1.validTime()+len);
177 Test_::model().forecast(xx1, Test_::bias(), len, post);
180 Test_::model().forecast(xx2, Test_::bias(), len, post);
183 EXPECT(xx1.validTime() == vt);
184 EXPECT(xx2.validTime() == vt);
187 oops::Log::debug() <<
"xx1.norm(): " << std::fixed << std::setprecision(8) << xx1.norm()
189 oops::Log::debug() <<
"xx2.norm(): " << std::fixed << std::setprecision(8) << xx2.norm()
193 EXPECT(xx1.norm() == xx2.norm());
196 EXPECT(Test_::xref().norm() == ininorm);
205 template <
typename MODEL>
211 std::string
testid()
const override {
return "test::Model<" + MODEL::name() +
">";}
214 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
216 ts.emplace_back(
CASE(
"interface/Model/testModelConstructor")
217 { testModelConstructor<MODEL>(); });
218 ts.emplace_back(
CASE(
"interface/Model/testModelNoForecast")
219 { testModelNoForecast<MODEL>(); });
220 ts.emplace_back(
CASE(
"interface/Model/testModelForecast")
221 { testModelForecast<MODEL>(); });
222 ts.emplace_back(
CASE(
"interface/Model/testModelReForecast")
223 { testModelReForecast<MODEL>(); });
233 #endif // TEST_INTERFACE_MODEL_H_