-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.cc
76 lines (71 loc) · 2.51 KB
/
test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// -*- mode: c++; coding: utf-8 -*-
// ra-ra/test - Tests for TestRecorder.
// (c) Daniel Llorens - 2021
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.
#include <iostream>
#include "ra/test.hh"
#include "mpdebug.hh"
using std::cout, std::endl, std::flush, ra::TestRecorder;
constexpr auto QNAN = std::numeric_limits<double>::quiet_NaN();
constexpr auto PINF = std::numeric_limits<double>::infinity();
int main()
{
TestRecorder tr(std::cout);
tr.section("amax_strict"); // cf amax() in reduction.cc.
{
tr.test(isnan(TestRecorder::amax_strict(ra::Small<double, 2>(QNAN))));
tr.test(isnan(TestRecorder::amax_strict(ra::Small<double, 2>(1, QNAN))));
tr.test(isnan(TestRecorder::amax_strict(ra::Small<double, 2>(QNAN, 1))));
tr.test_eq(9, TestRecorder::amax_strict(ra::Small<double, 2>{1, 9}));
tr.test_eq(9, TestRecorder::amax_strict(ra::Small<double, 2>{9, 1}));
}
tr.section("nan in numeric tests");
{
std::ostream devnull(nullptr);
TestRecorder ut(devnull);
tr.test(0==ut.summary());
ut.test_rel(0, QNAN, 1e-15);
tr.test(1==ut.summary());
ut.test_abs(0, QNAN, 1e-15);
tr.test(2==ut.summary());
}
tr.section("inf in numeric tests");
{
auto test = [&tr](bool fail, auto ref, auto a, auto err)
{
tr.expectfail(fail).test_abs(ref, a, err);
tr.expectfail(fail).test_rel(ref, a, err);
};
test(false, QNAN, QNAN, 0.);
test(false, PINF, PINF, 0.);
test(false, -PINF, -PINF, 0.);
test(true, QNAN, -PINF, 0.);
test(true, QNAN, PINF, 0.);
test(true, -PINF, QNAN, 0.);
test(true, PINF, QNAN, 0.);
test(true, PINF, -PINF, 0.);
test(true, -PINF, PINF, 0.);
test(true, 3., PINF, 0.);
test(true, 3., -PINF, 0.);
test(true, 3., QNAN, 0.);
test(true, PINF, 3., 0.);
test(true, -PINF, 3., 0.);
test(true, QNAN, 3., 0.);
}
tr.section("fov in test_abs/test_rel");
{
std::array ref = { 1., 2., 3. };
std::vector a = { 1., 2., 3. };
tr.test_abs(ref, a, 0.);
}
tr.section("export assumption");
{
tr.test(isfinite(3.));
tr.test(!isfinite(PINF));
tr.test(!isfinite(QNAN));
}
return tr.summary();
}