1+ #include < ALFI/spline/polyeqv.h>
2+
3+ #include " ../test_utils.h"
4+
5+ const auto test_data_path = TEST_DATA_DIR " /poly/poly.toml" ;
6+
7+ const auto test_data = toml::parse_file(test_data_path);
8+
9+ void test_polyeqv_spline (double epsilon) {
10+ const auto & test_cases = test_data[" test_cases" ].ref <toml::array>();
11+
12+ test_cases.for_each ([&](const toml::table& test_case) {
13+ const auto & X = to_vector<double >(test_case[" X" ].ref <toml::array>());
14+ const auto & Y = to_vector<double >(test_case[" Y" ].ref <toml::array>());
15+ const auto & xx = to_vector<double >(test_case[" xx" ].ref <toml::array>());
16+ const auto & yy = to_vector<double >(test_case[" yy" ].ref <toml::array>());
17+
18+ expect_eq (alfi::spline::PolyEqvSpline<>(X, Y).eval (xx), yy, epsilon);
19+ });
20+ }
21+
22+ TEST (PolyEqvSplineTest, PolynomialData) {
23+ test_polyeqv_spline (1e-10 );
24+ }
25+
26+ TEST (PolyEqvSplineTest, General) {
27+ const std::vector<double > X = {0 , 1 , 2 , 3 };
28+ const std::vector<double > Y = {5 , 2 , 10 , 4 };
29+ const auto spline = alfi::spline::PolyEqvSpline<>(X, Y);
30+ for (size_t i = 0 ; i < X.size () - 1 ; ++i) {
31+ EXPECT_EQ (spline (X[i]), Y[i]);
32+ }
33+ EXPECT_NEAR (spline (X[X.size ()-1 ]), Y[Y.size ()-1 ], 1e-14 );
34+ }
35+
36+ TEST (PolyEqvSplineTest, Moving) {
37+ std::vector<double > X = {0 , 1 , 2 , 3 };
38+ const std::vector<double > Y = {5 , 2 , 10 , 4 };
39+ auto spline = alfi::spline::PolyEqvSpline<>(std::move (X), Y);
40+ EXPECT_TRUE (X.empty ());
41+ EXPECT_FALSE (spline.X ().empty ());
42+ EXPECT_FALSE (spline.coeffs ().empty ());
43+ X = spline.X ();
44+ auto coeffs = spline.coeffs ();
45+ EXPECT_FALSE (X.empty ());
46+ EXPECT_FALSE (coeffs.empty ());
47+ EXPECT_FALSE (spline.X ().empty ());
48+ EXPECT_FALSE (spline.coeffs ().empty ());
49+ X = std::move (spline).X ();
50+ coeffs = std::move (spline).coeffs ();
51+ EXPECT_FALSE (X.empty ());
52+ EXPECT_FALSE (coeffs.empty ());
53+ EXPECT_TRUE (spline.X ().empty ());
54+ EXPECT_TRUE (spline.coeffs ().empty ());
55+ }
0 commit comments