FV3 Bundle
oops/src/test/interface/ObsVector.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef TEST_INTERFACE_OBSVECTOR_H_
12 #define TEST_INTERFACE_OBSVECTOR_H_
13 
14 #include <string>
15 #include <vector>
16 
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>
21 
22 #include <boost/scoped_ptr.hpp>
23 
25 #include "oops/runs/Test.h"
26 #include "oops/util/dot_product.h"
28 #include "test/TestEnvironment.h"
29 
30 namespace test {
31 
32 // -----------------------------------------------------------------------------
33 
34 template <typename MODEL> void testConstructor() {
35  typedef ObsTestsFixture<MODEL> Test_;
36  typedef oops::ObsVector<MODEL> ObsVector_;
37 
38  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
39  boost::scoped_ptr<ObsVector_> ov(new ObsVector_(Test_::obspace()[jj]));
40  BOOST_CHECK(ov.get());
41 
42  ov.reset();
43  BOOST_CHECK(!ov.get());
44  }
45 }
46 
47 // -----------------------------------------------------------------------------
48 
49 template <typename MODEL> void testCopyConstructor() {
50  typedef ObsTestsFixture<MODEL> Test_;
51  typedef oops::ObsVector<MODEL> ObsVector_;
52 
53  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
54  boost::scoped_ptr<ObsVector_> ov(new ObsVector_(Test_::obspace()[jj]));
55 
56  boost::scoped_ptr<ObsVector_> other(new ObsVector_(*ov));
57  BOOST_CHECK(other.get());
58 
59  other.reset();
60  BOOST_CHECK(!other.get());
61 
62  BOOST_CHECK(ov.get());
63  }
64 }
65 
66 // -----------------------------------------------------------------------------
67 
68 template <typename MODEL> void testNotZero() {
69  typedef ObsTestsFixture<MODEL> Test_;
70  typedef oops::ObsVector<MODEL> ObsVector_;
71  const double zero = 0.0;
72 
73  for (std::size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
74  ObsVector_ ov(Test_::obspace()[jj]);
75 
76  ov.random();
77 
78  const double ovov2 = dot_product(ov, ov);
79  BOOST_CHECK(ovov2 > zero);
80 
81  ov.zero();
82 
83  const double zz = dot_product(ov, ov);
84  BOOST_CHECK(zz == zero);
85  }
86 }
87 
88 // -----------------------------------------------------------------------------
89 
90 template <typename MODEL> class ObsVector : public oops::Test {
91  public:
92  ObsVector() {}
93  virtual ~ObsVector() {}
94  private:
95  std::string testid() const {return "test::ObsVector<" + MODEL::name() + ">";}
96 
97  void register_tests() const {
98  boost::unit_test::test_suite * ts = BOOST_TEST_SUITE("interface/ObsVector");
99 
100  ts->add(BOOST_TEST_CASE(&testConstructor<MODEL>));
101  ts->add(BOOST_TEST_CASE(&testCopyConstructor<MODEL>));
102  ts->add(BOOST_TEST_CASE(&testNotZero<MODEL>));
103 
104  boost::unit_test::framework::master_test_suite().add(ts);
105  }
106 };
107 
108 // =============================================================================
109 
110 } // namespace test
111 
112 #endif // TEST_INTERFACE_OBSVECTOR_H_
character(len=32) name
real(double), parameter zero
void testConstructor()
void testCopyConstructor()