~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/libnr/in-svg-plane-test.h

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <cxxtest/TestSuite.h>
2
 
 
3
 
#include <glib/gmacros.h>
4
 
#include <cmath>
5
 
 
6
 
#include "libnr/in-svg-plane.h"
7
 
#include "2geom/isnan.h"
8
 
 
9
 
class InSvgPlaneTest : public CxxTest::TestSuite
10
 
{
11
 
public:
12
 
 
13
 
    InSvgPlaneTest() :
14
 
        setupValid(true),
15
 
        p3n4( 3.0, -4.0 ),
16
 
        p0(0.0, 0.0),
17
 
        small( pow(2.0, -1070) ),
18
 
        inf( 1e400 ),
19
 
        nan( inf - inf ),
20
 
        small_left( -small, 0.0 ),
21
 
        small_n3_4( -3.0 * small, 4.0 * small ),
22
 
        part_nan( 3., nan )
23
 
    {
24
 
        setupValid &= IS_NAN(nan);
25
 
        setupValid &= !IS_NAN(small);
26
 
    }
27
 
    virtual ~InSvgPlaneTest() {}
28
 
 
29
 
// createSuite and destroySuite get us per-suite setup and teardown
30
 
// without us having to worry about static initialization order, etc.
31
 
    static InSvgPlaneTest *createSuite() { return new InSvgPlaneTest(); }
32
 
    static void destroySuite( InSvgPlaneTest *suite ) { delete suite; }
33
 
 
34
 
// Called before each test in this suite
35
 
    void setUp()
36
 
    {
37
 
        TS_ASSERT( setupValid );
38
 
    }
39
 
 
40
 
    bool setupValid;
41
 
    NR::Point const p3n4;
42
 
    NR::Point const p0;
43
 
    double const small;
44
 
    double const inf;
45
 
    double const nan;
46
 
    NR::Point const small_left;
47
 
    NR::Point const small_n3_4;
48
 
    NR::Point const part_nan;
49
 
 
50
 
 
51
 
    void testInSvgPlane(void)
52
 
    {
53
 
        TS_ASSERT( in_svg_plane(p3n4) );
54
 
        TS_ASSERT( in_svg_plane(p0) );
55
 
        TS_ASSERT( in_svg_plane(small_left) );
56
 
        TS_ASSERT( in_svg_plane(small_n3_4) );
57
 
        TS_ASSERT_DIFFERS( nan, nan );
58
 
        TS_ASSERT( !in_svg_plane(NR::Point(nan, 3.)) );
59
 
        TS_ASSERT( !in_svg_plane(NR::Point(inf, nan)) );
60
 
        TS_ASSERT( !in_svg_plane(NR::Point(0., -inf)) );
61
 
        double const xs[] = {inf, -inf, nan, 1., -2., small, -small};
62
 
        for (unsigned i = 0; i < G_N_ELEMENTS(xs); ++i) {
63
 
            for (unsigned j = 0; j < G_N_ELEMENTS(xs); ++j) {
64
 
                TS_ASSERT_EQUALS( in_svg_plane(NR::Point(xs[i], xs[j])),
65
 
                                  (fabs(xs[i]) < inf &&
66
 
                                   fabs(xs[j]) < inf   ) );
67
 
            }
68
 
        }
69
 
    }
70
 
};
71
 
 
72
 
/*
73
 
  Local Variables:
74
 
  mode:c++
75
 
  c-file-style:"stroustrup"
76
 
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
77
 
  indent-tabs-mode:nil
78
 
  fill-column:99
79
 
  End:
80
 
*/
81
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :