2 #ifndef SEEN_ROUND_TEST_H
3 #define SEEN_ROUND_TEST_H
5 #include <cxxtest/TestSuite.h>
7 #include <vector>
8 #include <round.h>
10 class RoundTest : public CxxTest::TestSuite
11 {
12 public:
13 struct Case {
14 double arg0;
15 double ret;
16 };
18 std::vector<Case> nonneg_round_cases;
19 std::vector<Case> nonpos_round_cases;
21 RoundTest() :
22 TestSuite()
23 {
24 Case cases[] = {
25 { 5.0, 5.0 },
26 { 0.0, 0.0 },
27 { 5.4, 5.0 },
28 { 5.6, 6.0 },
29 { 1e-7, 0.0 },
30 { 1e7 + .49, 1e7 },
31 { 1e7 + .51, 1e7 + 1 },
32 { 1e12 + .49, 1e12 },
33 { 1e12 + .51, 1e12 + 1 },
34 { 1e40, 1e40 }
35 };
37 for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ )
38 {
39 nonneg_round_cases.push_back( cases[i] );
41 Case tmp = {-nonneg_round_cases[i].arg0, -nonneg_round_cases[i].ret};
42 nonpos_round_cases.push_back( tmp );
43 }
44 }
46 virtual ~RoundTest()
47 {
48 }
50 static RoundTest *createSuite() { return new RoundTest(); }
51 static void destroySuite( RoundTest *suite ) { delete suite; }
53 // -------------------------------------------------------------------------
54 // -------------------------------------------------------------------------
58 void testNonNegRound()
59 {
60 for ( size_t i = 0; i < nonneg_round_cases.size(); i++ )
61 {
62 double result = Inkscape::round( nonneg_round_cases[i].arg0 );
63 TS_ASSERT_EQUALS( result, nonneg_round_cases[i].ret );
64 }
65 }
67 void testNonPosRoung()
68 {
69 for ( size_t i = 0; i < nonpos_round_cases.size(); i++ )
70 {
71 double result = Inkscape::round( nonpos_round_cases[i].arg0 );
72 TS_ASSERT_EQUALS( result, nonpos_round_cases[i].ret );
73 }
74 }
76 };
79 #endif // SEEN_ROUND_TEST_H
81 /*
82 Local Variables:
83 mode:c++
84 c-file-style:"stroustrup"
85 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
86 indent-tabs-mode:nil
87 fill-column:99
88 End:
89 */
90 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :