14 #include <boost/lexical_cast.hpp> 15 #include <boost/scoped_ptr.hpp> 16 #include <boost/test/unit_test.hpp> 19 #include "eckit/config/LocalConfiguration.h" 27 class ObsBiasTestFixture : TestFixture {
30 off_.reset(
new eckit::LocalConfiguration());
34 bias1_ = bconf.getDouble(
"bias");
39 boost::scoped_ptr<const eckit::LocalConfiguration>
off_;
40 boost::scoped_ptr<const eckit::LocalConfiguration>
conf_;
44 boost::scoped_ptr<lorenz95::ObsBias>
obias_;
52 BOOST_CHECK_EQUAL(dob.
value(), 0.0);
57 BOOST_CHECK_EQUAL(dob.
value(), 0.0);
62 dob1.
value() = bias1_;
66 BOOST_CHECK_EQUAL(dob2.
value(), bias1_);
71 dob1.
value() = bias1_;
77 BOOST_CHECK_EQUAL(dob2.
value(), 0.0);
82 dob1.
value() = bias1_;
88 BOOST_CHECK_EQUAL(dob2.
value(), 0.0);
93 dob1.
value() = bias1_;
99 BOOST_CHECK_EQUAL(dob2.
value(), 0.0);
104 dob1.
value() = bias1_;
108 BOOST_CHECK_EQUAL(dob2.
value(), bias1_);
113 dob1.
value() = bias1_;
119 BOOST_CHECK_EQUAL(dob2.
value(), 0.0);
124 obias2.
value() = bias2_;
128 dob.
diff(*obias_, obias2);
130 BOOST_CHECK_EQUAL(dob.
value(), bias1_ - bias2_);
135 obias2.
value() = bias2_;
140 dob.
diff(*obias_, obias2);
144 BOOST_CHECK_EQUAL(dob.
value(), 0.0);
149 dob.
value() = bias1_;
153 BOOST_CHECK_EQUAL(dob.
value(), 0.0);
158 dob1.
value() = bias1_;
160 dob2.
value() = bias2_;
164 BOOST_CHECK_EQUAL(dob1.
value(), bias2_);
169 dob1.
value() = bias1_;
171 dob2.
value() = bias2_;
176 BOOST_CHECK_EQUAL(dob1.
value(), 0.0);
181 dob1.
value() = bias1_;
183 dob2.
value() = bias2_;
187 BOOST_CHECK_EQUAL(dob1.
value(), bias1_ + bias2_);
192 dob1.
value() = bias1_;
194 dob2.
value() = bias2_;
199 BOOST_CHECK_EQUAL(dob1.
value(), bias1_);
204 dob1.
value() = bias1_;
206 dob2.
value() = bias2_;
210 BOOST_CHECK_EQUAL(dob1.
value(), bias1_ - bias2_);
215 dob1.
value() = bias1_;
217 dob2.
value() = bias2_;
222 BOOST_CHECK_EQUAL(dob1.
value(), bias1_);
227 dob.
value() = bias1_;
231 BOOST_CHECK_EQUAL(dob.
value(), bias1_ * fact_);
236 dob.
value() = bias1_;
241 BOOST_CHECK_EQUAL(dob.
value(), bias1_);
246 dob1.
value() = bias1_;
248 dob2.
value() = bias2_;
250 dob1.
axpy(fact_, dob2);
252 BOOST_CHECK_EQUAL(dob1.
value(), bias1_ + (fact_ * bias2_));
257 dob1.
value() = bias1_;
259 dob2.
value() = bias2_;
261 dob1.
axpy(fact_, dob2);
264 BOOST_CHECK_EQUAL(dob1.
value(), bias1_);
269 dob1.
value() = bias1_;
271 dob2.
value() = bias2_;
275 BOOST_CHECK_EQUAL(dpwResult, bias1_ * bias2_);
280 dob1.
value() = bias1_;
282 dob2.
value() = bias2_;
287 BOOST_CHECK_EQUAL(dpwResult, 0.0);
300 dob.
value() = bias1_;
304 std::string filename(
"ObsBiasCorrectionTest.txt");
306 std::ostream os(&fb);
311 std::string inputString;
312 std::string inputBias;
314 int biasStartPos = 20;
315 std::ifstream inputFile(filename.c_str());
316 if (inputFile.is_open()) {
317 getline(inputFile, inputString);
318 getline(inputFile, inputString);
320 inputBias = inputString.substr(biasStartPos);
323 bias = boost::lexical_cast<
double>(inputBias);
325 catch(boost::bad_lexical_cast
const&) {
326 BOOST_ERROR(
"operator<< incorrectly output a non-double");
329 BOOST_CHECK_CLOSE(bias1_, bias, 0.0001);
333 BOOST_ERROR(
"operator<< functionality cannot be determined");
339 BOOST_AUTO_TEST_SUITE_END()
boost::scoped_ptr< const eckit::LocalConfiguration > conf_
Class to handle observation bias parameters.
boost::scoped_ptr< const eckit::LocalConfiguration > off_
double dot_product_with(const ObsBiasCorrection &) const
boost::scoped_ptr< lorenz95::ObsBias > obias_
void axpy(const double, const ObsBiasCorrection &)
void diff(const ObsBias &, const ObsBias &)
Linear algebra operators.
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
const double & value() const