UFO
ProcessWhere.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef TEST_UFO_PROCESSWHERE_H_
9 #define TEST_UFO_PROCESSWHERE_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
15 
16 #include "eckit/config/LocalConfiguration.h"
17 #include "eckit/testing/Test.h"
18 #include "ioda/ObsSpace.h"
19 #include "oops/mpi/mpi.h"
20 #include "oops/runs/Test.h"
21 #include "oops/util/Logger.h"
22 #include "test/TestEnvironment.h"
25 #include "ufo/filters/Variables.h"
26 
27 namespace ufo {
28 namespace test {
29 
30 
31 // -----------------------------------------------------------------------------
32 
33 void testProcessWhere(const eckit::LocalConfiguration &conf,
34  bool is_in_usererror = false) {
35  util::DateTime bgn(conf.getString("window begin"));
36  util::DateTime end(conf.getString("window end"));
37 
38  eckit::LocalConfiguration obsconf(conf, "obs space");
39 
40  ioda::ObsSpace ospace(obsconf, oops::mpi::world(), bgn, end, oops::mpi::myself());
41  ObsFilterData data(ospace);
42 
43  const int nlocs = obsconf.getInt("nlocs");
44  EXPECT(data.nlocs() == nlocs);
45 
46  std::vector<eckit::LocalConfiguration> confs;
47  conf.get("ProcessWhere", confs);
48  for (size_t jconf = 0; jconf < confs.size(); ++jconf) {
49  eckit::LocalConfiguration config = confs[jconf];
50  if (is_in_usererror) {
51  EXPECT_THROWS(processWhere(config, data));
52  } else {
53  std::vector<bool> result = processWhere(config, data);
54  const int size_ref = config.getInt("size where true");
55  const int size = std::count(result.begin(), result.end(), true);
56  oops::Log::info() << "reference: " << size_ref << ", compare with " << size << std::endl;
57  EXPECT(size == size_ref);
58  }
59  }
60 }
61 
62 // -----------------------------------------------------------------------------
63 
64 class ProcessWhere : public oops::Test {
65  public:
67  virtual ~ProcessWhere() {}
68  private:
69  std::string testid() const override {return "ufo::test::ProcessWhere";}
70 
71  void register_tests() const override {
72  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
73 
74  ts.emplace_back(CASE("ufo/ProcessWhere/testProcessWhere_successful") {
75  testProcessWhere(eckit::LocalConfiguration(::test::TestEnvironment::config(),
76  "successful"));
77  });
78 
79  ts.emplace_back(CASE("ufo/ProcessWhere/testProcessWhere_isin_usererror") {
80  testProcessWhere(eckit::LocalConfiguration(::test::TestEnvironment::config(),
81  "user_error_type_handling_is_in"),
82  true);
83  });
84  }
85 
86  void clear() const override {}
87 };
88 
89 // -----------------------------------------------------------------------------
90 
91 } // namespace test
92 } // namespace ufo
93 
94 #endif // TEST_UFO_PROCESSWHERE_H_
ufo::test::ProcessWhere::ProcessWhere
ProcessWhere()
Definition: ProcessWhere.h:66
ufo::test::CASE
CASE("ufo/MetOfficeBuddyPairFinder/" "Duplicates, constraints on buddy counts, legacy pair collector")
Definition: test/ufo/MetOfficeBuddyPairFinder.h:171
ufo::test::ProcessWhere::clear
void clear() const override
Definition: ProcessWhere.h:86
processWhere.h
ufo::test::ProcessWhere::~ProcessWhere
virtual ~ProcessWhere()
Definition: ProcessWhere.h:67
ufo::processWhere
std::vector< bool > processWhere(const eckit::Configuration &config, const ObsFilterData &filterdata)
Definition: processWhere.cc:203
ufo
Definition: RunCRTM.h:27
Variables.h
ufo::test::testProcessWhere
void testProcessWhere(const eckit::LocalConfiguration &conf, bool is_in_usererror=false)
Definition: ProcessWhere.h:33
ufo::test::ProcessWhere::testid
std::string testid() const override
Definition: ProcessWhere.h:69
ufo::test::ProcessWhere
Definition: ProcessWhere.h:64
ObsFilterData.h
ufo::test::ObsFilterData
Definition: test/ufo/ObsFilterData.h:212
conf
Definition: conf.py:1
ufo::test::ProcessWhere::register_tests
void register_tests() const override
Definition: ProcessWhere.h:71