diff --git a/tests/misc/test_barycentric.cpp b/tests/misc/test_barycentric.cpp index 8a84ca8..da1f5fb 100644 --- a/tests/misc/test_barycentric.cpp +++ b/tests/misc/test_barycentric.cpp @@ -1,35 +1,39 @@ -#include +#include -#include -#include +#include "../test_utils.h" -#include +void test_barycentric(const toml::parse_result& test_data, double epsilon) { + const auto& test_cases = test_data["test_cases"].ref(); -template -void test_case(const std::vector& X, const std::vector& Y, - const std::vector& xx, - alfi::dist::Type dist_type, - const std::vector& yy) { - EXPECT_EQ(alfi::misc::barycentric(X, Y, xx, dist_type), yy); -} + test_cases.for_each([&](const toml::table& test_case) { + const auto& X = to_vector(test_case["X"].ref()); + const auto& Y = to_vector(test_case["Y"].ref()); + const auto& xx = to_vector(test_case["xx"].ref()); + const auto& dist = test_case["dist"].ref(); + const auto& yy = to_vector(test_case["yy"].ref()); -template -void test_case(const std::vector& X, const std::vector& Y, const std::vector& xx, const std::vector& yy) { - EXPECT_EQ(alfi::misc::barycentric(X, Y, xx), yy); -} + const auto& dist_type + = dist == "uniform" ? + alfi::dist::Type::UNIFORM + : dist == "chebyshev" ? + alfi::dist::Type::CHEBYSHEV + : dist == "chebyshev_2" ? + alfi::dist::Type::CHEBYSHEV_2 + : alfi::dist::Type::GENERAL; -template -void test_case(const std::vector& X, const std::vector& Y, alfi::dist::Type dist_type) { - EXPECT_EQ(alfi::misc::barycentric(X, Y, X, dist_type), Y); + expect_eq(alfi::misc::barycentric(X, Y, xx, dist_type), yy, epsilon); + }); } -template -void test_case(const std::vector& X, const std::vector& Y) { - EXPECT_EQ(alfi::misc::barycentric(X, Y, X), Y); +// barycentric formula can also be tested on the polynomial data +TEST(BarycentricTest, PolynomialData) { + const auto polynomial_test_data_path = TEST_DATA_DIR "/poly/poly.toml"; + const auto polynomial_test_data = toml::parse_file(polynomial_test_data_path); + test_barycentric(polynomial_test_data, 1e-12); } -TEST(BarycentricTest, Basic) { - test_case({0, 1, 2}, {0, 0, 0}); - test_case({0, 1, 2}, {1, 1, 1}); - test_case({0, 1, 2}, {1, 2, 3}); +TEST(BarycentricTest, BarycentricData) { + const auto barycentric_test_data_path = TEST_DATA_DIR "/misc/barycentric.toml"; + const auto barycentric_test_data = toml::parse_file(barycentric_test_data_path); + test_barycentric(barycentric_test_data, 1e-13); } \ No newline at end of file diff --git a/tests/test_data b/tests/test_data index b743ee0..456cebc 160000 --- a/tests/test_data +++ b/tests/test_data @@ -1 +1 @@ -Subproject commit b743ee09d375c7202c638cc0c17d4fdb4d5cf6c6 +Subproject commit 456cebc19bf0e01c5a06a610dc63a9f71ecadade