2
#include <cxxtest/TestSuite.h>
4
#include "libnr/types.h"
5
#include "libnr/point-fns.h"
11
class NrTypesTest : public CxxTest::TestSuite
18
small(pow(2.0, -1070)),
19
small_left(-small, 0.0),
20
smallish_3_neg4(3.0 * small, -4.0 * small)
22
virtual ~NrTypesTest() {}
24
// createSuite and destroySuite get us per-suite setup and teardown
25
// without us having to worry about static initialization order, etc.
26
static NrTypesTest *createSuite() { return new NrTypesTest(); }
27
static void destroySuite( NrTypesTest *suite ) { delete suite; }
33
Point const small_left;
34
Point const smallish_3_neg4;
37
void testXYValues( void )
39
TS_ASSERT_EQUALS( X, 0 );
40
TS_ASSERT_EQUALS( Y, 1 );
43
void testXYCtorAndArrayConst(void)
45
TS_ASSERT_EQUALS( a[X], 1.5 );
46
TS_ASSERT_EQUALS( a[Y], 2.0 );
49
void testCopyCtor(void)
51
Geom::Point a_copy(a);
53
TS_ASSERT_EQUALS( a, a_copy );
54
TS_ASSERT( !(a != a_copy) );
57
void testNonConstArrayOperator(void)
59
Geom::Point a_copy(a);
61
TS_ASSERT_DIFFERS( a_copy, a );
62
TS_ASSERT_DIFFERS( a_copy, b );
64
TS_ASSERT_EQUALS( a_copy, b );
67
void testBinaryPlusMinus(void)
69
TS_ASSERT_DIFFERS( a, b );
70
TS_ASSERT_EQUALS( a + b, ab );
71
TS_ASSERT_EQUALS( ab - a, b );
72
TS_ASSERT_EQUALS( ab - b, a );
73
TS_ASSERT_DIFFERS( ab + a, b );
76
void testUnaryMinus(void)
78
TS_ASSERT_EQUALS( -a, Point(-a[X], -a[Y]) );
81
void tetScaleDivide(void)
83
TS_ASSERT_EQUALS( -a, -1.0 * a );
84
TS_ASSERT_EQUALS( a + a + a, 3.0 * a );
85
TS_ASSERT_EQUALS( a / .5, 2.0 * a );
90
TS_ASSERT_EQUALS( dot(a, b), ( a[X] * b[X] +
92
TS_ASSERT_EQUALS( dot(a, Geom::rot90(a)), 0.0 );
93
TS_ASSERT_EQUALS( dot(-a, Geom::rot90(a)), 0.0 );
96
void testL1L2LInftyNorms(void)
98
// TODO look at TS_ASSERT_DELTA
100
TS_ASSERT_EQUALS( L1(small_left), small );
101
TS_ASSERT_EQUALS( L2(small_left), small );
102
TS_ASSERT_EQUALS( LInfty(small_left), small );
104
TS_ASSERT_EQUALS( L1(smallish_3_neg4), 7.0 * small );
105
TS_ASSERT_EQUALS( L2(smallish_3_neg4), 5.0 * small );
106
TS_ASSERT_EQUALS( LInfty(smallish_3_neg4), 4.0 * small );
109
void testOperatorPlusEquals(void)
113
TS_ASSERT_EQUALS( x, ab );
116
void tetOperatorDivEquals(void)
120
TS_ASSERT_EQUALS( x, a + a );
123
void testNormalize(void)
127
TS_ASSERT_EQUALS( x, Point(-1.0, 0.0) );
131
TS_ASSERT_EQUALS( x, Point(0.6, -0.8) );
139
c-file-style:"stroustrup"
140
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
145
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :