Skip to content

Commit 99a895f

Browse files
authoredMar 5, 2024··
Cleanup tests (#40)
--------- Co-authored-by: Alexander Voigt <alexander.voigt@physik.rwth-aachen.de>
1 parent bc64f88 commit 99a895f

17 files changed

+80
-169
lines changed
 

‎test/test.hpp

+56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
11
#pragma once
22

3+
#include <cmath>
4+
#include <complex>
5+
6+
7+
#ifndef M_PI
8+
#define M_PI 3.1415926535897932
9+
#endif
10+
11+
12+
#define CHECK_CLOSE(a,b,eps) \
13+
do { \
14+
if (std::isinf(a) && std::isinf(b)) { \
15+
CHECK(true); \
16+
} else { \
17+
CHECK((a) == doctest::Approx(b).epsilon(eps)); \
18+
} \
19+
} while (0);
20+
21+
22+
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
23+
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
24+
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
25+
} while (0)
26+
27+
28+
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
29+
30+
31+
inline bool has_inf() noexcept
32+
{
33+
return std::isinf(std::numeric_limits<double>::max() + 1.0);
34+
}
35+
36+
337
inline bool has_signed_zero() noexcept
438
{
539
const auto fn = [] (double x) { return x == 0.0 ? x : x; };
640
return std::signbit(fn(-0.0));
741
}
42+
43+
44+
template <class T> T sqr(T x) {
45+
return x*x;
46+
}
47+
48+
49+
template <class T> T pow3(T x) {
50+
return x*x*x;
51+
}
52+
53+
54+
template <class T> T pow4(T x) {
55+
return sqr(sqr(x));
56+
}
57+
58+
59+
template <typename T, typename U>
60+
std::complex<T> to(std::complex<U> z)
61+
{
62+
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
63+
}

‎test/test_Cl.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515
#include <complex>
1616
#include <vector>
1717

18-
#ifndef M_PI
19-
#define M_PI 3.1415926535897932
20-
#endif
21-
22-
#define CHECK_CLOSE(a,b,eps) do { \
23-
if (std::isinf(a) && std::isinf(b)) \
24-
CHECK(true); \
25-
else \
26-
CHECK((a) == doctest::Approx(b).epsilon(eps)); \
27-
} while (0);
28-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
29-
3018
std::vector<double> float_range(
3119
double start, double stop, std::size_t number_of_steps)
3220
{

‎test/test_Cl1.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#include "doctest.h"
44
#include "Cl1.hpp"
55
#include "read_data.hpp"
6+
#include "test.hpp"
67
#include <cmath>
78

8-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
9-
109
TEST_CASE("test_real_fixed_values")
1110
{
1211
const auto eps64 = std::pow(10.0 , -std::numeric_limits<double>::digits10);

‎test/test_Cl2.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@
1313
#include <limits>
1414
#include <vector>
1515

16-
#ifndef M_PI
17-
#define M_PI 3.1415926535897932
18-
#endif
19-
2016
#ifdef ENABLE_GSL
2117
#include <gsl/gsl_sf_clausen.h>
2218
#endif
2319

24-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
25-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
26-
2720
namespace {
2821

2922
double poly_Cl2(double x) {

‎test/test_Cl3.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@
77
#include "fortran_wrappers.h"
88
#include "Li3.hpp"
99
#include "read_data.hpp"
10+
#include "test.hpp"
1011
#include <cmath>
1112
#include <complex>
1213
#include <vector>
1314

14-
#ifndef M_PI
15-
#define M_PI 3.1415926535897932
16-
#endif
17-
18-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
19-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
20-
2115
std::vector<double> float_range(
2216
double start, double stop, std::size_t number_of_steps)
2317
{

‎test/test_Cl4.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
#include <complex>
1212
#include <vector>
1313

14-
#ifndef M_PI
15-
#define M_PI 3.1415926535897932
16-
#endif
17-
18-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
19-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
20-
2114
std::vector<double> float_range(
2215
double start, double stop, std::size_t number_of_steps)
2316
{

‎test/test_Cl5.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
#include "fortran_wrappers.h"
77
#include "Li5.hpp"
88
#include "read_data.hpp"
9+
#include "test.hpp"
910
#include <cmath>
1011
#include <complex>
1112
#include <vector>
1213

13-
#ifndef M_PI
14-
#define M_PI 3.1415926535897932
15-
#endif
16-
17-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
18-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
19-
2014
#ifdef ENABLE_FORTRAN
2115

2216
double poly_Cl5_fortran(double x) {

‎test/test_Cl6.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
#include <complex>
1212
#include <vector>
1313

14-
#ifndef M_PI
15-
#define M_PI 3.1415926535897932
16-
#endif
17-
18-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
19-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) <= (eps))
20-
2114
double poly_Cl6(double x) {
2215
return cl6(x);
2316
}

‎test/test_Li.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
#include <complex>
99
#include <string>
1010

11-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
12-
13-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
14-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
15-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
16-
} while (0)
17-
18-
/*
19-
2011
TEST_CASE("test_infinite_values")
2112
{
13+
if (!has_inf()) {
14+
return;
15+
}
16+
2217
using polylogarithm::Li;
2318

2419
for (int n = -10; n <= 0; ++n) {
@@ -27,8 +22,6 @@ TEST_CASE("test_infinite_values")
2722
}
2823
}
2924

30-
*/
31-
3225
TEST_CASE("test_complex_fixed_values")
3326
{
3427
using polylogarithm::Li;

‎test/test_Li2.cpp

+4-29
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include <random>
1515
#include <vector>
1616

17-
#ifndef M_PI
18-
#define M_PI 3.1415926535897932
19-
#endif
20-
2117
#ifdef ENABLE_GSL
2218

2319
#include <gsl/gsl_sf_dilog.h>
@@ -36,22 +32,7 @@ std::complex<double> gsl_Li2(std::complex<double> z) {
3632

3733
#endif
3834

39-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
40-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
41-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
42-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
43-
} while (0)
44-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
45-
4635
const std::complex<double> omega(0.5, std::sqrt(3.)/2.);
47-
const std::complex<double> zero(0.,0.);
48-
49-
template <class T> T sqr(T x) { return x*x; }
50-
51-
bool is_unity(std::complex<long double> z, long double eps)
52-
{
53-
return std::abs(std::real(z) - 1.0L) <= eps && std::imag(z) == 0.0L;
54-
}
5536

5637
/// special values to be checked
5738
const std::vector<std::complex<double>> special_values = {
@@ -81,12 +62,6 @@ std::complex<double> clog(std::complex<double> z) {
8162
return std::log(zf);
8263
}
8364

84-
template <typename T, typename U>
85-
std::complex<T> to(std::complex<U> z)
86-
{
87-
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
88-
}
89-
9065
std::complex<double> hdecay_Li2(std::complex<double> z) {
9166
double li2_re{}, li2_im{};
9267
hdecay_dilog(std::real(z), std::imag(z), &li2_re, &li2_im);
@@ -180,7 +155,7 @@ const auto Relation_2 = [](std::complex<double> z) {
180155
using polylogarithm::Li2;
181156

182157
if (std::abs(z) < 1e-10 || std::real(z) < 0.) {
183-
return zero;
158+
return std::complex<double>(0.0, 0.0);
184159
}
185160

186161
return Li2(1.-z) + Li2(1.-1./z) + clog(z)*clog(z)/2.;
@@ -190,7 +165,7 @@ const auto Relation_3 = [](std::complex<double> z) {
190165
using polylogarithm::Li2;
191166

192167
if (std::abs(z) < 1e-10 || std::abs(std::real(z) - 1.) < 1e-10) {
193-
return zero;
168+
return std::complex<double>(0.0, 0.0);
194169
}
195170

196171
return Li2(z) + Li2(1.-z)
@@ -202,7 +177,7 @@ const auto Relation_4 = [](std::complex<double> z) {
202177

203178
if (std::abs(z) < 1e-10 || std::abs(std::real(z) + 1.) < 1e-10
204179
|| std::real(z) < 0. || std::imag(z) < 0.) {
205-
return zero;
180+
return std::complex<double>(0.0, 0.0);
206181
}
207182

208183
return Li2(-z) - Li2(1.-z) + Li2(1.-z*z)/2.
@@ -214,7 +189,7 @@ const auto Relation_5 = [](std::complex<double> z) {
214189

215190
if (std::abs(z) < 1e-10
216191
|| (std::real(z) > 0. && std::real(z) < 1.)) {
217-
return zero;
192+
return std::complex<double>(0.0, 0.0);
218193
}
219194

220195
return Li2(z) + Li2(1./z)

‎test/test_Li3.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
#include <limits>
1313
#include <utility>
1414

15-
#ifndef M_PI
16-
#define M_PI 3.1415926535897932
17-
#endif
18-
19-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
20-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
21-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
22-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
23-
} while (0)
24-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
25-
26-
template <class T> T sqr(T x) { return x*x; }
27-
template <class T> T pow3(T x) { return x*x*x; }
28-
2915
std::complex<double> clog(std::complex<double> z) {
3016
std::complex<double> zf(z);
3117
// convert -0.0 to 0.0
@@ -34,12 +20,6 @@ std::complex<double> clog(std::complex<double> z) {
3420
return std::log(zf);
3521
}
3622

37-
template <typename T, typename U>
38-
std::complex<T> to(std::complex<U> z)
39-
{
40-
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
41-
}
42-
4323
double poly_Li3(double z) {
4424
return li3(z);
4525
}

‎test/test_Li4.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@
1111
#include <limits>
1212
#include <utility>
1313

14-
#ifndef M_PI
15-
#define M_PI 3.1415926535897932
16-
#endif
17-
18-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
19-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
20-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
21-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
22-
} while (0)
23-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
24-
25-
template <class T> T sqr(T x) { return x*x; }
26-
template <class T> T pow4(T x) { return x*x*x*x; }
27-
28-
template <typename T, typename U>
29-
std::complex<T> to(std::complex<U> z)
30-
{
31-
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
32-
}
33-
3414
double poly_Li4(double z) {
3515
return li4(z);
3616
}

‎test/test_Li5.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@
1111
#include <limits>
1212
#include <utility>
1313

14-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
15-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
16-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
17-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
18-
} while (0)
19-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
20-
21-
template <typename T, typename U>
22-
std::complex<T> to(std::complex<U> z)
23-
{
24-
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
25-
}
26-
2714
std::complex<double> poly_Li5(std::complex<double> z) {
2815
double re{}, im{};
2916
cli5_c(std::real(z), std::imag(z), &re, &im);

‎test/test_Li6.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@
1111
#include <limits>
1212
#include <utility>
1313

14-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
15-
#define CHECK_CLOSE_COMPLEX(a,b,eps) do { \
16-
CHECK_CLOSE(std::real(a), std::real(b), (eps)); \
17-
CHECK_CLOSE(std::imag(a), std::imag(b), (eps)); \
18-
} while (0)
19-
#define CHECK_SMALL(a,eps) CHECK(std::abs(a) < (eps))
20-
21-
template <typename T, typename U>
22-
std::complex<T> to(std::complex<U> z)
23-
{
24-
return std::complex<T>(static_cast<T>(std::real(z)), static_cast<T>(std::imag(z)));
25-
}
26-
2714
std::complex<double> poly_Li6(std::complex<double> z) {
2815
double re{}, im{};
2916
cli6_c(std::real(z), std::imag(z), &re, &im);

‎test/test_Sl.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
#include <cmath>
99
#include <complex>
1010

11-
#define CHECK_CLOSE(a,b,eps) do { \
12-
if (std::isinf(a) && std::isinf(b)) \
13-
CHECK(true); \
14-
else \
15-
CHECK((a) == doctest::Approx(b).epsilon(eps)); \
16-
} while (0);
17-
1811
double Sl_via_Li(int64_t n, double x)
1912
{
2013
const std::complex<double> li = polylogarithm::Li(n, std::polar(1.0, x));

‎test/test_harmonic.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#include "doctest.h"
44
#include "harmonic.hpp"
5-
6-
#define CHECK_CLOSE(a,b,eps) CHECK((a) == doctest::Approx(b).epsilon(eps))
5+
#include "test.hpp"
76

87
TEST_CASE("test_fixed_values")
98
{

‎test/test_zeta.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 1
22

33
#include "doctest.h"
4+
#include "test.hpp"
45
#include "zeta.hpp"
6+
#include <cmath>
57

68
TEST_CASE("test_fixed_values")
79
{
810
using polylogarithm::zeta;
9-
const double PI = 3.1415926535897932;
1011

11-
// CHECK(std::isinf(zeta(-263)));
12+
if (has_inf()) {
13+
CHECK(std::isinf(zeta(-263)));
14+
}
1215
CHECK(zeta(-262) == 0.0);
13-
// CHECK(std::isinf(zeta(-261)));
16+
if (has_inf()) {
17+
CHECK(std::isinf(zeta(-261)));
18+
}
1419
CHECK(zeta(-259) == 8.7601563446229215e306);
1520
CHECK(zeta(-257) == -5.1754977470366798e303);
1621
CHECK(zeta(-255) == 3.1055517596048927e300);
@@ -19,8 +24,10 @@ TEST_CASE("test_fixed_values")
1924
CHECK(zeta(-2) == 0.0);
2025
CHECK(zeta(-1) == -1.0/12.0);
2126
CHECK(zeta(0) == -0.5);
22-
// CHECK(std::isinf(zeta(1)));
23-
CHECK(zeta(2) == PI*PI/6.0);
27+
if (has_inf()) {
28+
CHECK(std::isinf(zeta(1)));
29+
}
30+
CHECK(zeta(2) == M_PI*M_PI/6.0);
2431
CHECK(zeta(32) == 1.0000000002328312);
2532
CHECK(zeta(33) == 1.0000000001164155);
2633
CHECK(zeta(34) == 1.0000000000582077);

0 commit comments

Comments
 (0)
Please sign in to comment.