Skip to content

Commit a0fd8aa

Browse files
authored
Merge pull request #18 from steppi/test_fix
TST:CI: Make some improvements to data driven tests
2 parents a544ee2 + 827928b commit a0fd8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1097
-10
lines changed

.github/workflows/linux.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ jobs:
5252
- name: Install Catch2
5353
run: |
5454
cmake -Bbuild -H. -DBUILD_TESTING=OFF
55-
sudo cmake --build build/ --target install
55+
sudo cmake --build build/ --target install -j2
5656
working-directory: ./Catch2
5757

5858
- name: Configure and build
5959
run: |
60-
cmake .
61-
make
60+
cmake -Bbuild
61+
cmake --build build -j2
6262
6363
- name: run tests
6464
run: |
65-
ctest --output-on-failure
65+
ctest --output-on-failure --test-dir build/tests -j2

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ CMakeUserPresets.json
4848
DartConfiguration.tcl
4949

5050
# test executable extension
51-
*.test
51+
build/

include/xsf/stats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ inline double bdtrc(double k, int n, double p) { return cephes::bdtrc(k, n, p);
2525

2626
inline double chdtr(double df, double x) { return cephes::chdtr(df, x); }
2727

28+
inline float chdtr(float df, float x) { return static_cast<float>(cephes::chdtr(df, x)); }
29+
2830
inline double chdtrc(double df, double x) { return cephes::chdtrc(df, x); }
2931

32+
inline float chdtrc(float df, float x) { return static_cast<float>(cephes::chdtrc(df, x)); }
33+
3034
inline double chdtri(double df, double y) { return cephes::chdtri(df, y); }
3135

3236
inline double fdtr(double a, double b, double x) { return cephes::fdtr(a, b, x); }

tests/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ find_package(Parquet REQUIRED)
1111
add_library(xsf INTERFACE)
1212
target_include_directories(xsf INTERFACE ${CMAKE_SOURCE_DIR}/include)
1313

14+
set(TEST_BASE_DIR "${CMAKE_SOURCE_DIR}/tests")
15+
1416
file(GLOB TEST_SOURCES "*/test_*.cpp")
1517
foreach(test_file ${TEST_SOURCES})
18+
# Families of tests go in subfolders of xsf/tests. Test files in different
19+
# folders can have the same name. Try to generate a unique target name based
20+
# on the test name and its parent folder(s).
1621
get_filename_component(test_name ${test_file} NAME_WE)
17-
add_executable(${test_name}.test ${test_file})
18-
target_link_libraries(${test_name}.test PRIVATE Catch2::Catch2WithMain Arrow::arrow_shared Parquet::parquet_shared xsf)
19-
target_compile_definitions(${test_name}.test PRIVATE XSREF_TABLES_PATH="${XSREF_TABLES_PATH}")
22+
get_filename_component(test_dir ${test_file} DIRECTORY)
23+
file(RELATIVE_PATH test_dir ${TEST_BASE_DIR} ${test_dir})
24+
string(REPLACE "/" "-" test_dir ${test_dir})
25+
set(target_name ${test_dir}_${test_name})
26+
27+
add_executable(${target_name} ${test_file})
28+
29+
target_link_libraries(${target_name} PRIVATE Catch2::Catch2WithMain Arrow::arrow_shared Parquet::parquet_shared xsf)
30+
31+
target_compile_definitions(${target_name} PRIVATE XSREF_TABLES_PATH="${XSREF_TABLES_PATH}")
2032
include(CTest)
2133
include(Catch)
22-
catch_discover_tests(${test_name}.test)
34+
catch_discover_tests(${target_name})
2335
endforeach()

tests/scipy_special_tests/test_airy.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,44 @@ TEST_CASE("airy D->DDDD scipy_special_tests", "[airy][D->DDDD][scipy_special_tes
4949
CAPTURE(z, out3, desired3, error3, tol3, fallback);
5050
REQUIRE(error3 <= tol3);
5151
}
52+
53+
TEST_CASE("airy d->dddd scipy_special_tests", "[airy][d->dddd][scipy_special_tests]") {
54+
SET_FP_FORMAT()
55+
auto [input, output, tol] =
56+
GENERATE(xsf_test_cases<
57+
double, std::tuple<double, double, double, double, bool>, std::tuple<double, double, double, double>>(
58+
tables_path / "In_d-d_d_d_d.parquet", tables_path / "Out_d-d_d_d_d.parquet",
59+
tables_path / ("Err_d-d_d_d_d_" + get_platform_str() + ".parquet")
60+
));
61+
62+
auto z = input;
63+
auto [desired0, desired1, desired2, desired3, fallback] = output;
64+
65+
double out0;
66+
double out1;
67+
double out2;
68+
double out3;
69+
70+
xsf::airy(z, out0, out1, out2, out3);
71+
auto [tol0, tol1, tol2, tol3] = tol;
72+
73+
auto error0 = xsf::extended_relative_error(out0, desired0);
74+
tol0 = adjust_tolerance(tol0);
75+
CAPTURE(z, out0, desired0, error0, tol0, fallback);
76+
REQUIRE(error0 <= tol0);
77+
78+
auto error1 = xsf::extended_relative_error(out1, desired1);
79+
tol1 = adjust_tolerance(tol1);
80+
CAPTURE(z, out1, desired1, error1, tol1, fallback);
81+
REQUIRE(error1 <= tol1);
82+
83+
auto error2 = xsf::extended_relative_error(out2, desired2);
84+
tol2 = adjust_tolerance(tol2);
85+
CAPTURE(z, out2, desired2, error2, tol2, fallback);
86+
REQUIRE(error2 <= tol2);
87+
88+
auto error3 = xsf::extended_relative_error(out3, desired3);
89+
tol3 = adjust_tolerance(tol3);
90+
CAPTURE(z, out3, desired3, error3, tol3, fallback);
91+
REQUIRE(error3 <= tol3);
92+
}

tests/scipy_special_tests/test_airye.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,44 @@ TEST_CASE("airye D->DDDD scipy_special_tests", "[airye][D->DDDD][scipy_special_t
4949
CAPTURE(z, out3, desired3, error3, tol3, fallback);
5050
REQUIRE(error3 <= tol3);
5151
}
52+
53+
TEST_CASE("airye d->dddd scipy_special_tests", "[airye][d->dddd][scipy_special_tests]") {
54+
SET_FP_FORMAT()
55+
auto [input, output, tol] =
56+
GENERATE(xsf_test_cases<
57+
double, std::tuple<double, double, double, double, bool>, std::tuple<double, double, double, double>>(
58+
tables_path / "In_d-d_d_d_d.parquet", tables_path / "Out_d-d_d_d_d.parquet",
59+
tables_path / ("Err_d-d_d_d_d_" + get_platform_str() + ".parquet")
60+
));
61+
62+
auto z = input;
63+
auto [desired0, desired1, desired2, desired3, fallback] = output;
64+
65+
double out0;
66+
double out1;
67+
double out2;
68+
double out3;
69+
70+
xsf::airye(z, out0, out1, out2, out3);
71+
auto [tol0, tol1, tol2, tol3] = tol;
72+
73+
auto error0 = xsf::extended_relative_error(out0, desired0);
74+
tol0 = adjust_tolerance(tol0);
75+
CAPTURE(z, out0, desired0, error0, tol0, fallback);
76+
REQUIRE(error0 <= tol0);
77+
78+
auto error1 = xsf::extended_relative_error(out1, desired1);
79+
tol1 = adjust_tolerance(tol1);
80+
CAPTURE(z, out1, desired1, error1, tol1, fallback);
81+
REQUIRE(error1 <= tol1);
82+
83+
auto error2 = xsf::extended_relative_error(out2, desired2);
84+
tol2 = adjust_tolerance(tol2);
85+
CAPTURE(z, out2, desired2, error2, tol2, fallback);
86+
REQUIRE(error2 <= tol2);
87+
88+
auto error3 = xsf::extended_relative_error(out3, desired3);
89+
tol3 = adjust_tolerance(tol3);
90+
CAPTURE(z, out3, desired3, error3, tol3, fallback);
91+
REQUIRE(error3 <= tol3);
92+
}

tests/scipy_special_tests/test_bdtr.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ TEST_CASE("bdtr dpd->d scipy_special_tests", "[bdtr][dpd->d][scipy_special_tests
2222
CAPTURE(k, n, p, out, desired, error, tol, fallback);
2323
REQUIRE(error <= tol);
2424
}
25+
26+
TEST_CASE("bdtr ddd->d scipy_special_tests", "[bdtr][ddd->d][scipy_special_tests]") {
27+
SET_FP_FORMAT()
28+
auto [input, output, tol] =
29+
GENERATE(xsf_test_cases<std::tuple<double, double, double>, std::tuple<double, bool>, double>(
30+
tables_path / "In_d_d_d-d.parquet", tables_path / "Out_d_d_d-d.parquet",
31+
tables_path / ("Err_d_d_d-d_" + get_platform_str() + ".parquet")
32+
));
33+
34+
auto [k, n, p] = input;
35+
auto [desired, fallback] = output;
36+
auto out = xsf::bdtr(k, n, p);
37+
auto error = xsf::extended_relative_error(out, desired);
38+
tol = adjust_tolerance(tol);
39+
CAPTURE(k, n, p, out, desired, error, tol, fallback);
40+
REQUIRE(error <= tol);
41+
}

tests/scipy_special_tests/test_bdtrc.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ TEST_CASE("bdtrc dpd->d scipy_special_tests", "[bdtrc][dpd->d][scipy_special_tes
2222
CAPTURE(k, n, p, out, desired, error, tol, fallback);
2323
REQUIRE(error <= tol);
2424
}
25+
26+
TEST_CASE("bdtrc ddd->d scipy_special_tests", "[bdtrc][ddd->d][scipy_special_tests]") {
27+
SET_FP_FORMAT()
28+
auto [input, output, tol] =
29+
GENERATE(xsf_test_cases<std::tuple<double, double, double>, std::tuple<double, bool>, double>(
30+
tables_path / "In_d_d_d-d.parquet", tables_path / "Out_d_d_d-d.parquet",
31+
tables_path / ("Err_d_d_d-d_" + get_platform_str() + ".parquet")
32+
));
33+
34+
auto [k, n, p] = input;
35+
auto [desired, fallback] = output;
36+
auto out = xsf::bdtrc(k, n, p);
37+
auto error = xsf::extended_relative_error(out, desired);
38+
tol = adjust_tolerance(tol);
39+
CAPTURE(k, n, p, out, desired, error, tol, fallback);
40+
REQUIRE(error <= tol);
41+
}

tests/scipy_special_tests/test_bdtri.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ TEST_CASE("bdtri dpd->d scipy_special_tests", "[bdtri][dpd->d][scipy_special_tes
2222
CAPTURE(k, n, y, out, desired, error, tol, fallback);
2323
REQUIRE(error <= tol);
2424
}
25+
26+
TEST_CASE("bdtri ddd->d scipy_special_tests", "[bdtri][ddd->d][scipy_special_tests]") {
27+
SET_FP_FORMAT()
28+
auto [input, output, tol] =
29+
GENERATE(xsf_test_cases<std::tuple<double, double, double>, std::tuple<double, bool>, double>(
30+
tables_path / "In_d_d_d-d.parquet", tables_path / "Out_d_d_d-d.parquet",
31+
tables_path / ("Err_d_d_d-d_" + get_platform_str() + ".parquet")
32+
));
33+
34+
auto [k, n, y] = input;
35+
auto [desired, fallback] = output;
36+
auto out = xsf::bdtri(k, n, y);
37+
auto error = xsf::extended_relative_error(out, desired);
38+
tol = adjust_tolerance(tol);
39+
CAPTURE(k, n, y, out, desired, error, tol, fallback);
40+
REQUIRE(error <= tol);
41+
}

tests/scipy_special_tests/test_chdtr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ TEST_CASE("chdtr dd->d scipy_special_tests", "[chdtr][dd->d][scipy_special_tests
2121
CAPTURE(v, x, out, desired, error, tol, fallback);
2222
REQUIRE(error <= tol);
2323
}
24+
25+
TEST_CASE("chdtr ff->f scipy_special_tests", "[chdtr][ff->f][scipy_special_tests]") {
26+
SET_FP_FORMAT()
27+
auto [input, output, tol] = GENERATE(xsf_test_cases<std::tuple<float, float>, std::tuple<float, bool>, float>(
28+
tables_path / "In_f_f-f.parquet", tables_path / "Out_f_f-f.parquet",
29+
tables_path / ("Err_f_f-f_" + get_platform_str() + ".parquet")
30+
));
31+
32+
auto [v, x] = input;
33+
auto [desired, fallback] = output;
34+
auto out = xsf::chdtr(v, x);
35+
auto error = xsf::extended_relative_error(out, desired);
36+
tol = adjust_tolerance(tol);
37+
CAPTURE(v, x, out, desired, error, tol, fallback);
38+
REQUIRE(error <= tol);
39+
}

0 commit comments

Comments
 (0)