~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/libnr/nr-point-fns-test.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// nr-point-fns-test.h
 
2
#include <cxxtest/TestSuite.h>
 
3
 
 
4
#include <cassert>
 
5
#include <cmath>
 
6
#include <glib/gmacros.h>
 
7
#include <stdlib.h>
 
8
 
 
9
#include "libnr/nr-point-fns.h"
 
10
#include "2geom/isnan.h"
 
11
 
 
12
class NrPointFnsTest : public CxxTest::TestSuite
 
13
{
 
14
public:
 
15
    NrPointFnsTest() :
 
16
        setupValid(true),
 
17
        p3n4( 3.0, -4.0 ),
 
18
        p0( 0.0, 0.0 ),
 
19
        small( pow( 2.0, -1070 ) ),
 
20
        inf( 1e400 ),
 
21
        nan( inf - inf ),
 
22
        small_left( -small, 0.0 ),
 
23
        small_n3_4( -3.0 * small, 4.0 * small ),
 
24
        part_nan( 3., nan ),
 
25
        inf_left( -inf, 5.0 )
 
26
    {
 
27
        TS_ASSERT( IS_NAN(nan) );
 
28
        TS_ASSERT( !IS_NAN(small) );
 
29
 
 
30
        setupValid &= IS_NAN(nan);
 
31
        setupValid &= !IS_NAN(small);
 
32
    }
 
33
    virtual ~NrPointFnsTest() {}
 
34
 
 
35
// createSuite and destroySuite get us per-suite setup and teardown
 
36
// without us having to worry about static initialization order, etc.
 
37
    static NrPointFnsTest *createSuite() { return new NrPointFnsTest(); }
 
38
    static void destroySuite( NrPointFnsTest *suite ) { delete suite; }
 
39
 
 
40
// Called before each test in this suite
 
41
    void setUp()
 
42
    {
 
43
        TS_ASSERT( setupValid );
 
44
    }
 
45
 
 
46
    bool setupValid;
 
47
    NR::Point const p3n4;
 
48
    NR::Point const p0;
 
49
    double const small;
 
50
    double const inf;
 
51
    double const nan;
 
52
 
 
53
    NR::Point const small_left;
 
54
    NR::Point const small_n3_4;
 
55
    NR::Point const part_nan;
 
56
    NR::Point const inf_left;
 
57
 
 
58
 
 
59
    void testL1(void)
 
60
    {
 
61
        TS_ASSERT_EQUALS( NR::L1(p0), 0.0  );
 
62
        TS_ASSERT_EQUALS( NR::L1(p3n4), 7.0  );
 
63
        TS_ASSERT_EQUALS( NR::L1(small_left), small  );
 
64
        TS_ASSERT_EQUALS( NR::L1(inf_left), inf  );
 
65
        TS_ASSERT_EQUALS( NR::L1(small_n3_4), 7.0 * small  );
 
66
        TS_ASSERT(IS_NAN(NR::L1(part_nan)));
 
67
    }
 
68
 
 
69
    void testL2(void)
 
70
    {
 
71
        TS_ASSERT_EQUALS( NR::L2(p0), 0.0 );
 
72
        TS_ASSERT_EQUALS( NR::L2(p3n4), 5.0 );
 
73
        TS_ASSERT_EQUALS( NR::L2(small_left), small );
 
74
        TS_ASSERT_EQUALS( NR::L2(inf_left), inf );
 
75
        TS_ASSERT_EQUALS( NR::L2(small_n3_4), 5.0 * small );
 
76
        TS_ASSERT( IS_NAN(NR::L2(part_nan)) );
 
77
    }
 
78
 
 
79
    void testLInfty(void)
 
80
    {
 
81
        TS_ASSERT_EQUALS( NR::LInfty(p0), 0.0 );
 
82
        TS_ASSERT_EQUALS( NR::LInfty(p3n4), 4.0 );
 
83
        TS_ASSERT_EQUALS( NR::LInfty(small_left), small );
 
84
        TS_ASSERT_EQUALS( NR::LInfty(inf_left), inf );
 
85
        TS_ASSERT_EQUALS( NR::LInfty(small_n3_4), 4.0 * small );
 
86
        TS_ASSERT( IS_NAN(NR::LInfty(part_nan)) );
 
87
    }
 
88
 
 
89
    void testIsZero(void)
 
90
    {
 
91
        TS_ASSERT( NR::is_zero(p0) );
 
92
        TS_ASSERT( !NR::is_zero(p3n4) );
 
93
        TS_ASSERT( !NR::is_zero(small_left) );
 
94
        TS_ASSERT( !NR::is_zero(inf_left) );
 
95
        TS_ASSERT( !NR::is_zero(small_n3_4) );
 
96
        TS_ASSERT( !NR::is_zero(part_nan) );
 
97
    }
 
98
 
 
99
    void testAtan2(void)
 
100
    {
 
101
        TS_ASSERT_EQUALS( NR::atan2(p3n4), atan2(-4.0, 3.0) );
 
102
        TS_ASSERT_EQUALS( NR::atan2(small_left), atan2(0.0, -1.0) );
 
103
        TS_ASSERT_EQUALS( NR::atan2(small_n3_4), atan2(4.0, -3.0) );
 
104
    }
 
105
 
 
106
    void testUnitVector(void)
 
107
    {
 
108
        TS_ASSERT_EQUALS( NR::unit_vector(p3n4), NR::Point(.6, -0.8) );
 
109
        TS_ASSERT_EQUALS( NR::unit_vector(small_left), NR::Point(-1.0, 0.0) );
 
110
        TS_ASSERT_EQUALS( NR::unit_vector(small_n3_4), NR::Point(-.6, 0.8) );
 
111
    }
 
112
 
 
113
    void testIsUnitVector(void)
 
114
    {
 
115
        TS_ASSERT( !NR::is_unit_vector(p3n4) );
 
116
        TS_ASSERT( !NR::is_unit_vector(small_left) );
 
117
        TS_ASSERT( !NR::is_unit_vector(small_n3_4) );
 
118
        TS_ASSERT( !NR::is_unit_vector(part_nan) );
 
119
        TS_ASSERT( !NR::is_unit_vector(inf_left) );
 
120
        TS_ASSERT( !NR::is_unit_vector(NR::Point(.5, 0.5)) );
 
121
        TS_ASSERT( NR::is_unit_vector(NR::Point(.6, -0.8)) );
 
122
        TS_ASSERT( NR::is_unit_vector(NR::Point(-.6, 0.8)) );
 
123
        TS_ASSERT( NR::is_unit_vector(NR::Point(-1.0, 0.0)) );
 
124
        TS_ASSERT( NR::is_unit_vector(NR::Point(1.0, 0.0)) );
 
125
        TS_ASSERT( NR::is_unit_vector(NR::Point(0.0, -1.0)) );
 
126
        TS_ASSERT( NR::is_unit_vector(NR::Point(0.0, 1.0)) );
 
127
    }
 
128
};
 
129
 
 
130
/*
 
131
  Local Variables:
 
132
  mode:c++
 
133
  c-file-style:"stroustrup"
 
134
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
135
  indent-tabs-mode:nil
 
136
  fill-column:99
 
137
  End:
 
138
*/
 
139
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :