~lib2geom-hackers/lib2geom/trunk

« back to all changes in this revision

Viewing changes to scale-test.h

  • Committer: njh
  • Date: 2006-05-22 11:50:24 UTC
  • Revision ID: svn-v4:4601daaa-0314-0410-9a8b-c964a3c23b6b:trunk/lib2geom:1
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cxxtest/TestSuite.h>
 
2
 
 
3
#include <libnr/scale.h>
 
4
#include <libnr/scale-ops.h>
 
5
using Geom::X;
 
6
using Geom::Y;
 
7
 
 
8
class NrScaleTest : public CxxTest::TestSuite
 
9
{
 
10
public:
 
11
 
 
12
    NrScaleTest() :
 
13
        sa( 1.5, 2.0 ),
 
14
        b( -2.0, 3.0 ),
 
15
        sb( b )
 
16
    {
 
17
    }
 
18
    virtual ~NrScaleTest() {}
 
19
 
 
20
// createSuite and destroySuite get us per-suite setup and teardown
 
21
// without us having to worry about static initialization order, etc.
 
22
    static NrScaleTest *createSuite() { return new NrScaleTest(); }
 
23
    static void destroySuite( NrScaleTest *suite ) { delete suite; }
 
24
 
 
25
    Geom::scale const sa;
 
26
    Geom::Point const b;
 
27
    Geom::scale const sb;
 
28
 
 
29
 
 
30
 
 
31
    void testXY_CtorArrayOperator(void)
 
32
    {
 
33
        TS_ASSERT_EQUALS( sa[X], 1.5 );
 
34
        TS_ASSERT_EQUALS( sa[Y], 2.0 );
 
35
        TS_ASSERT_EQUALS( sa[0u], 1.5 );
 
36
        TS_ASSERT_EQUALS( sa[1u], 2.0 );
 
37
    }
 
38
 
 
39
 
 
40
    void testCopyCtor_AssignmentOp_NotEquals(void)
 
41
    {
 
42
        Geom::scale const sa_copy(sa);
 
43
        TS_ASSERT_EQUALS( sa, sa_copy );
 
44
        TS_ASSERT(!( sa != sa_copy ));
 
45
        TS_ASSERT( sa != sb );
 
46
    }
 
47
 
 
48
    void testAssignmentOp(void)
 
49
    {
 
50
        Geom::scale sa_eq(sb);
 
51
        sa_eq = sa;
 
52
        TS_ASSERT_EQUALS( sa, sa_eq );
 
53
    }
 
54
 
 
55
    void testPointCtor(void)
 
56
    {
 
57
        TS_ASSERT_EQUALS( sb[X], b[X] );
 
58
        TS_ASSERT_EQUALS( sb[Y], b[Y] );
 
59
    }
 
60
 
 
61
    void testOpStarPointScale(void)
 
62
    {
 
63
        Geom::Point const ab( b * sa );
 
64
        TS_ASSERT_EQUALS( ab, Geom::Point(-3.0, 6.0) );
 
65
    }
 
66
 
 
67
    void testOpStarScaleScale(void)
 
68
    {
 
69
        Geom::scale const sab( sa * sb );
 
70
        TS_ASSERT_EQUALS( sab, Geom::scale(-3.0, 6.0) );
 
71
    }
 
72
 
 
73
    void testOpDivScaleScale(void)
 
74
    {
 
75
        Geom::scale const sa_b( sa / sb );
 
76
        Geom::scale const exp_sa_b(-0.75, 2./3.);
 
77
        TS_ASSERT_EQUALS( sa_b[0], exp_sa_b[0] );
 
78
//      TS_ASSERT_EQUALS( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 );
 
79
        TS_ASSERT_DELTA( sa_b[1], exp_sa_b[1], 1e-10 );
 
80
    }
 
81
};
 
82
 
 
83
/*
 
84
  Local Variables:
 
85
  mode:c++
 
86
  c-file-style:"stroustrup"
 
87
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
88
  indent-tabs-mode:nil
 
89
  fill-column:99
 
90
  End:
 
91
*/
 
92
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :