Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ endmacro()

add_test_executable(test_dist dist/test_dist.cpp)

add_test_executable(test_lagrange poly/test_lagrange.cpp poly/test_case.h)
add_test_executable(test_imp_lagrange poly/test_imp_lagrange.cpp poly/test_case.h)
add_test_executable(test_newton poly/test_newton.cpp poly/test_case.h)
add_test_executable(test_poly poly/test_poly.cpp)

add_test_executable(test_barycentric misc/test_barycentric.cpp)

Expand Down
47 changes: 0 additions & 47 deletions tests/poly/test_case.h

This file was deleted.

35 changes: 0 additions & 35 deletions tests/poly/test_imp_lagrange.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions tests/poly/test_lagrange.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions tests/poly/test_newton.cpp

This file was deleted.

44 changes: 44 additions & 0 deletions tests/poly/test_poly.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <ALFI/poly.h>

#include "../test_utils.h"

const auto test_data_path = TEST_DATA_DIR "/poly/poly.toml";

const auto test_data = toml::parse_file(test_data_path);

void test_polynomial(const auto& function_coeffs, const auto& function_vals,
double epsilon_coeffs, double epsilon_values, double epsilon_vals) {
const auto& test_cases = test_data["test_cases"].ref<toml::array>();

test_cases.for_each([&](const toml::table& test_case) {
const auto& X = to_vector<double>(test_case["X"].ref<toml::array>());
const auto& Y = to_vector<double>(test_case["Y"].ref<toml::array>());
const auto& coeffs = to_vector<double>(test_case["coeffs"].ref<toml::array>());
const auto& xx = to_vector<double>(test_case["xx"].ref<toml::array>());
const auto& yy = to_vector<double>(test_case["yy"].ref<toml::array>());

const auto P = function_coeffs(X, Y);
expect_eq(P, coeffs, epsilon_coeffs);
const auto values = alfi::poly::val(P, xx);
expect_eq(values, yy, epsilon_values);
const auto vals = function_vals(X, Y, xx);
expect_eq(vals, yy, epsilon_vals);
});
}

// need this workaround because of the fourth parameter of `alfi::poly::imp_lagrange_vals`
static const auto& imp_lagrange_vals = [](const auto& X, const auto& Y, const auto& xx) {
return alfi::poly::imp_lagrange_vals<>(X, Y, xx);
};

TEST(PolynomialsTest, Lagrange) {
test_polynomial(alfi::poly::lagrange<>, alfi::poly::lagrange_vals<>, 1e-7, 1e-1, 1e-11);
}

TEST(PolynomialsTest, ImprovedLagrange) {
test_polynomial(alfi::poly::imp_lagrange<>, imp_lagrange_vals, 1e-4, 1e-4, 1e-11);
}

TEST(PolynomialsTest, Newton) {
test_polynomial(alfi::poly::newton<>, alfi::poly::newton_vals<>, 1e-8, 1e-4, 1e-5);
}