UFO
test/ufo/PiecewiseLinearInterpolation.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 Met Office UK
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_PIECEWISELINEARINTERPOLATION_H_
9 #define TEST_UFO_PIECEWISELINEARINTERPOLATION_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include "eckit/config/LocalConfiguration.h"
15 #include "eckit/testing/Test.h"
16 #include "oops/runs/Test.h"
17 #include "oops/util/Expect.h"
18 #include "test/TestEnvironment.h"
20 
21 namespace ufo {
22 namespace test {
23 
24 CASE("ufo/PiecewiseLinearInterpolation/atInterpolationPoints") {
25  ufo::PiecewiseLinearInterpolation interp({-1.0, 1.0, 5.0}, {2.0, 4.0, 0.0});
26 
27  EXPECT_EQUAL(interp(-1.0), 2.0);
28  EXPECT_EQUAL(interp(1.0), 4.0);
29  EXPECT_EQUAL(interp(5.0), 0.0);
30 }
31 
32 CASE("ufo/PiecewiseLinearInterpolation/betweenInterpolationPoints") {
33  ufo::PiecewiseLinearInterpolation interp({-1.0, 1.0, 5.0}, {2.0, 4.0, 0.0});
34 
35  EXPECT_EQUAL(interp(0.0), 3.0);
36  EXPECT_EQUAL(interp(2.0), 3.0);
37 }
38 
39 CASE("ufo/PiecewiseLinearInterpolation/outsideInterpolationPoints") {
40  ufo::PiecewiseLinearInterpolation interp({-1.0, 1.0, 5.0}, {2.0, 4.0, 0.0});
41 
42  EXPECT_EQUAL(interp(-10.0), 2.0);
43  EXPECT_EQUAL(interp(10.0), 0.0);
44 }
45 
46 CASE("ufo/PiecewiseLinearInterpolation/singleInterpolationPoint") {
47  ufo::PiecewiseLinearInterpolation interp({-1.0}, {2.0});
48 
49  EXPECT_EQUAL(interp(-10.0), 2.0);
50  EXPECT_EQUAL(interp(-1.0), 2.0);
51  EXPECT_EQUAL(interp(10.0), 2.0);
52 }
53 
54 CASE("ufo/PiecewiseLinearInterpolation/noInterpolationPoints") {
55  EXPECT_THROWS(ufo::PiecewiseLinearInterpolation({}, {}));
56 }
57 
58 CASE("ufo/PiecewiseLinearInterpolation/differentNumberOfAbscissasAndOrdinates") {
59  EXPECT_THROWS(ufo::PiecewiseLinearInterpolation({1.0, 2.0}, {1.0, 2.0, 3.0}));
60  EXPECT_THROWS(ufo::PiecewiseLinearInterpolation({1.0, 2.0, 3.0}, {1.0, 2.0}));
61 }
62 
63 class PiecewiseLinearInterpolation : public oops::Test {
64  private:
65  std::string testid() const override {return "ufo::test::PiecewiseLinearInterpolation";}
66 
67  void register_tests() const override {}
68 
69  void clear() const override {}
70 };
71 
72 } // namespace test
73 } // namespace ufo
74 
75 #endif // TEST_UFO_PIECEWISELINEARINTERPOLATION_H_
Represents a piecewise linear interpolation of a set of data points.
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
Definition: RunCRTM.h:27