UFO
test/ufo/Locations.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UK Met Office
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_LOCATIONS_H_
9 #define TEST_UFO_LOCATIONS_H_
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
16 
17 #include "eckit/config/LocalConfiguration.h"
18 #include "eckit/testing/Test.h"
19 #include "ioda/ObsSpace.h"
20 #include "oops/mpi/mpi.h"
21 #include "oops/runs/Test.h"
22 #include "oops/util/DateTime.h"
23 #include "oops/util/Duration.h"
24 #include "oops/util/Logger.h"
25 #include "test/TestEnvironment.h"
26 #include "ufo/Locations.h"
27 
28 namespace ufo {
29 namespace test {
30 // -----------------------------------------------------------------------------
31 
32 void testLocations() {
33  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
34 
35  // Setup ObsSpace
36  util::DateTime bgn(conf.getString("window begin"));
37  util::DateTime end(conf.getString("window end"));
38  const eckit::LocalConfiguration obsconf(conf, "obs space");
39  ioda::ObsSpace odb(obsconf, oops::mpi::world(), bgn, end, oops::mpi::myself());
40  const size_t nlocs = odb.nlocs();
41 
42  // testConstructor:: Locations():
43  Locations locs(oops::mpi::world());
44  EXPECT(locs.nobs() == 0);
45  oops::Log::test() << "Locs(eckit mpi communicator): " << locs << std::endl;
46 
47  // testConstructor:: Locations(const eckit::Configuration &)
48  Locations locs1(conf, oops::mpi::world());
49  EXPECT(locs1.nobs() == nlocs);
50  oops::Log::test() << "Locs(eckit constructor, eckit mpi communicator): " << locs1 << std::endl;
51 
52  // testConstructor::Locations(const ioda::ObsSpace &, const util::DateTime &,
53  // const util::DateTime &);
54  Locations locs_t(odb, bgn, end);
55  EXPECT(locs_t.nobs() == nlocs);
56  oops::Log::test() << "Locs(odb,t1,t2) constructor): " << locs_t << std::endl;
57 
58  // test operator+=(const Locations & other)
59  util::Duration twin = end - bgn;
60  util::DateTime stateTime = bgn + twin/2;
61 
62  Locations locs_b(odb, stateTime, end);
63  const size_t nlocs_b = locs_b.nobs();
64  oops::Log::test() << "Locs(odb,t1+(t2-t1)/2,t2) constructor): " << locs_b << std::endl;
65 
66  {
67  Locations locs_a(odb, bgn, stateTime);
68  const size_t nlocs_a = locs_a.nobs();
69  oops::Log::test() << "Locs(odb,t1,t1+(t2-t1)/2) constructor): " << locs_a << std::endl;
70 
71  EXPECT(locs_t.nobs() == nlocs_a + nlocs_b);
72 
73  locs_a += locs_b;
74  EXPECT(locs_t.nobs() == locs_a.nobs());
75  oops::Log::test() << "Locs(odb,t1,t1+(t2-t1)/2) + "
76  << "Locs(odb,t1+(t2-t1)/2,t2) concatenated: " << locs_a << std::endl;
77  }
78  Locations locs_a(odb, bgn, stateTime);
79  locs_b += locs_a;
80  EXPECT(locs_t.nobs() == locs_b.nobs());
81  oops::Log::test() << "Locs(odb,t1+(t2-t1)/2,t2) + "
82  << "Locs(odb,t1,t1+(t2-t1)/2) concatenated: " << locs_b << std::endl;
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 class Locations : public oops::Test {
88  public:
89  Locations() {}
90  virtual ~Locations() {}
91  private:
92  std::string testid() const override {return "ufo::test::Locations";}
93 
94  void register_tests() const override {
95  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
96 
97  ts.emplace_back(CASE("ufo/Locations/testLocations")
98  { testLocations(); });
99  }
100 
101  void clear() const override {}
102 };
103 
104 // -----------------------------------------------------------------------------
105 
106 } // namespace test
107 } // namespace ufo
108 
109 #endif // TEST_UFO_LOCATIONS_H_
ufo::test::Locations::register_tests
void register_tests() const override
Definition: test/ufo/Locations.h:94
ufo::test::CASE
CASE("ufo/MetOfficeBuddyPairFinder/" "Duplicates, constraints on buddy counts, legacy pair collector")
Definition: test/ufo/MetOfficeBuddyPairFinder.h:171
ufo::test::Locations::Locations
Locations()
Definition: test/ufo/Locations.h:89
ufo
Definition: RunCRTM.h:27
ufo::test::Locations::~Locations
virtual ~Locations()
Definition: test/ufo/Locations.h:90
ufo::test::testLocations
void testLocations()
Definition: test/ufo/Locations.h:32
ufo::test::Locations::testid
std::string testid() const override
Definition: test/ufo/Locations.h:92
ufo::test::Locations::clear
void clear() const override
Definition: test/ufo/Locations.h:101
ufo::test::Locations
Definition: test/ufo/Locations.h:87
conf
Definition: conf.py:1