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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include <cassert>
#include <functional>
#include <glib/gmacros.h>
#include <utest/test-1ary-cases.h>
#include <utest/utest.h>
#include <round.h>
static Case1<double, double> const nonneg_round_cases[] = {
{ 5.0, 5.0 },
{ 0.0, 0.0 },
{ 5.4, 5.0 },
{ 5.6, 6.0 },
{ 1e-7, 0.0 },
{ 1e7 + .49, 1e7 },
{ 1e7 + .51, 1e7 + 1 },
{ 1e12 + .49, 1e12 },
{ 1e12 + .51, 1e12 + 1 },
{ 1e40, 1e40 }
};
static Case1<double, double> nonpos_round_cases[G_N_ELEMENTS(nonneg_round_cases)];
static void fill_nonpos_round_cases()
{
assert(G_N_ELEMENTS(nonneg_round_cases) == G_N_ELEMENTS(nonpos_round_cases));
for(unsigned i = 0; i < G_N_ELEMENTS(nonpos_round_cases); ++i) {
nonpos_round_cases[i].f_arg0 = -nonneg_round_cases[i].f_arg0;
nonpos_round_cases[i].valid_arg0 = -nonneg_round_cases[i].valid_arg0;
}
}
static bool
test_round()
{
utest_start("round");
test_1ary_cases<double, double, double, std::equal_to<double> >
("non-neg round",
Inkscape::round,
G_N_ELEMENTS(nonneg_round_cases), nonneg_round_cases);
fill_nonpos_round_cases();
test_1ary_cases<double, double, double, std::equal_to<double> >
("non-pos round",
Inkscape::round,
G_N_ELEMENTS(nonpos_round_cases), nonpos_round_cases);
#if 0
for(unsigned i = 0; i < G_N_ELEMENTS(round_cases); ++i) {
RoundCase const &c = round_cases[i];
double const got = Inkscape::round(c.unrounded);
UTEST_ASSERT( got == c.exp_rounded );
double const neg_got = Inkscape::round(-c.unrounded);
UTEST_ASSERT( neg_got = -c.exp_rounded );
}
#endif
return utest_end();
}
#if 0
/* Deliberately down here just to ensure that correct behaviour of Inkscape::round doesn't depend
on #including decimal-round.h. (decimal-round.h already #includes round.h, so there's no point
checking the other way around.) */
#include <decimal-round.h>
static void
test_decimal_round()
{
}
#endif
int main()
{
int const ret = ( test_round()
? EXIT_SUCCESS
: EXIT_FAILURE );
return ret;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|