11 #ifndef TEST_INTERFACE_OBSSPACE_H_ 12 #define TEST_INTERFACE_OBSSPACE_H_ 17 #define BOOST_TEST_NO_MAIN 18 #define BOOST_TEST_ALTERNATIVE_INIT_API 19 #define BOOST_TEST_DYN_LINK 20 #include <boost/test/unit_test.hpp> 22 #include <boost/noncopyable.hpp> 23 #include <boost/scoped_ptr.hpp> 25 #include "eckit/config/LocalConfiguration.h" 27 #include "ioda/ObsSpace.h" 38 typedef ::test::ObsTestsFixture<ioda::IodaTrait> Test_;
48 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
49 BOOST_CHECK_EQUAL(Test_::obspace()[jj].windowStart(), Test_::tbgn());
50 BOOST_CHECK_EQUAL(Test_::obspace()[jj].windowEnd(), Test_::tend());
52 Odb = &(Test_::obspace()[jj].observationspace());
59 const eckit::Configuration & Conf(Odb->
config());
60 ExpectedNobs = Conf.getInt(
"ObsData.ObsDataIn.metadata.nobs");
61 ExpectedNlocs = Conf.getInt(
"ObsData.ObsDataIn.metadata.nlocs");
63 BOOST_CHECK_EQUAL(Nobs, ExpectedNobs);
64 BOOST_CHECK_EQUAL(Nlocs, ExpectedNlocs);
71 typedef ::test::ObsTestsFixture<ioda::IodaTrait> Test_;
80 std::vector<std::string> VarNames;
81 std::vector<double> ExpectedVnorms;
83 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
86 Odb = &(Test_::obspace()[jj].observationspace());
89 const eckit::Configuration & Conf(Odb->
config());
90 VarNames = Conf.getStringVector(
"ObsData.ObsDataIn.TestData.variables");
91 ExpectedVnorms = Conf.getDoubleVector(
"ObsData.ObsDataIn.TestData.norms");
92 Tol = Conf.getDouble(
"ObsData.ObsDataIn.TestData.tolerance");
95 for (std::size_t
i = 0;
i < VarNames.size(); ++
i) {
97 std::vector<double> TestVec(Nlocs);
102 for (std::size_t
j = 0;
j < Nlocs; ++
j) {
103 Vnorm += pow(TestVec[
j], 2.0);
107 BOOST_CHECK_CLOSE(Vnorm, ExpectedVnorms[
i], Tol);
115 typedef ::test::ObsTestsFixture<ioda::IodaTrait> Test_;
122 std::string VarName(
"DummyVector");
124 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
127 Odb = &(Test_::obspace()[jj].observationspace());
132 Nlocs = Odb->
nlocs();
133 std::vector<double> TestVec(Nlocs);
134 std::vector<double> ExpectedVec(Nlocs);
136 for (std::size_t
i = 0;
i < Nlocs; ++
i) {
146 for (std::size_t
i = 0;
i < Nlocs; ++
i) {
147 VecMatch = VecMatch && (int(ExpectedVec[
i]) == int(TestVec[
i]));
150 BOOST_CHECK(VecMatch);
157 typedef ::test::ObsTestsFixture<ioda::IodaTrait> Test_;
166 std::vector<std::string> VarNames;
167 std::vector<double> ExpectedVnorms;
169 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
172 Odb = &(Test_::obspace()[jj].observationspace());
175 const eckit::Configuration & Conf(Odb->
config());
176 VarNames = Conf.getStringVector(
"ObsData.ObsDataIn.TestData.variables");
177 ExpectedVnorms = Conf.getDoubleVector(
"ObsData.ObsDataIn.TestData.norms");
178 Tol = Conf.getDouble(
"ObsData.ObsDataIn.TestData.tolerance");
180 Nlocs = Odb->
nlocs();
181 for (std::size_t
i = 0;
i < VarNames.size(); ++
i) {
183 std::vector<double> TestVec(Nlocs);
184 Odb->
get_db(
"MetaData", VarNames[
i], Nlocs, TestVec.data());
188 for (std::size_t
j = 0;
j < Nlocs; ++
j) {
189 Vnorm += pow(TestVec[
j], 2.0);
193 BOOST_CHECK_CLOSE(Vnorm, ExpectedVnorms[
i], Tol);
201 typedef ::test::ObsTestsFixture<ioda::IodaTrait> Test_;
208 std::string VarName(
"DummyRow");
210 for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
213 Odb = &(Test_::obspace()[jj].observationspace());
218 Nlocs = Odb->
nlocs();
219 std::vector<double> TestVec(Nlocs);
220 std::vector<double> ExpectedVec(Nlocs);
222 for (std::size_t
i = 0;
i < Nlocs; ++
i) {
228 Odb->
put_db(
"MetaData", VarName, Nlocs, ExpectedVec.data());
229 Odb->
get_db(
"MetaData", VarName, Nlocs, TestVec.data());
232 for (std::size_t
i = 0;
i < Nlocs; ++
i) {
233 VecMatch = VecMatch && (int(ExpectedVec[
i]) == int(TestVec[
i]));
236 BOOST_CHECK(VecMatch);
247 std::string
testid()
const {
return "test::ObsSpace<ioda::IodaTrait>";}
250 boost::unit_test::test_suite * ts = BOOST_TEST_SUITE(
"ObsSpace");
258 boost::unit_test::framework::master_test_suite().add(ts);
267 #endif // TEST_INTERFACE_OBSSPACE_H_ void get_db(const std::string &, const std::string &, const std::size_t &, int[]) const
l_size ! loop over number of fields ke do je do i
integer, parameter, public double
Wrapper around ObsHelpQG, mostly to hide the factory.
l_size ! loop over number of fields ke do j
std::string testid() const
void getObsVector(const std::string &, std::vector< double > &) const
void putObsVector(const std::string &, const std::vector< double > &) const
void register_tests() const
void put_db(const std::string &, const std::string &, const std::size_t &, const int[]) const
const eckit::Configuration & config() const
Access information.