1 #include <cassert>
2 #include <functional>
3 #include <glib/gmacros.h>
5 #include <utest/test-1ary-cases.h>
6 #include <utest/utest.h>
7 #include <round.h>
9 static Case1<double, double> const nonneg_round_cases[] = {
10 { 5.0, 5.0 },
11 { 0.0, 0.0 },
12 { 5.4, 5.0 },
13 { 5.6, 6.0 },
14 { 1e-7, 0.0 },
15 { 1e7 + .49, 1e7 },
16 { 1e7 + .51, 1e7 + 1 },
17 { 1e12 + .49, 1e12 },
18 { 1e12 + .51, 1e12 + 1 },
19 { 1e40, 1e40 }
20 };
22 static Case1<double, double> nonpos_round_cases[G_N_ELEMENTS(nonneg_round_cases)];
24 static void fill_nonpos_round_cases()
25 {
26 assert(G_N_ELEMENTS(nonneg_round_cases) == G_N_ELEMENTS(nonpos_round_cases));
27 for(unsigned i = 0; i < G_N_ELEMENTS(nonpos_round_cases); ++i) {
28 nonpos_round_cases[i].f_arg0 = -nonneg_round_cases[i].f_arg0;
29 nonpos_round_cases[i].valid_arg0 = -nonneg_round_cases[i].valid_arg0;
30 }
31 }
33 static bool
34 test_round()
35 {
36 utest_start("round");
37 test_1ary_cases<double, double, double, std::equal_to<double> >
38 ("non-neg round",
39 Inkscape::round,
40 G_N_ELEMENTS(nonneg_round_cases), nonneg_round_cases);
42 fill_nonpos_round_cases();
44 test_1ary_cases<double, double, double, std::equal_to<double> >
45 ("non-pos round",
46 Inkscape::round,
47 G_N_ELEMENTS(nonpos_round_cases), nonpos_round_cases);
49 #if 0
50 for(unsigned i = 0; i < G_N_ELEMENTS(round_cases); ++i) {
51 RoundCase const &c = round_cases[i];
52 double const got = Inkscape::round(c.unrounded);
53 UTEST_ASSERT( got == c.exp_rounded );
55 double const neg_got = Inkscape::round(-c.unrounded);
56 UTEST_ASSERT( neg_got = -c.exp_rounded );
57 }
58 #endif
59 return utest_end();
60 }
62 #if 0
63 /* Deliberately down here just to ensure that correct behaviour of Inkscape::round doesn't depend
64 on #including decimal-round.h. (decimal-round.h already #includes round.h, so there's no point
65 checking the other way around.) */
66 #include <decimal-round.h>
68 static void
69 test_decimal_round()
70 {
71 }
72 #endif
74 int main()
75 {
76 int const ret = ( test_round()
77 ? EXIT_SUCCESS
78 : EXIT_FAILURE );
79 return ret;
80 }
82 /*
83 Local Variables:
84 mode:c++
85 c-file-style:"stroustrup"
86 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
87 indent-tabs-mode:nil
88 fill-column:99
89 End:
90 */
91 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :