~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/libnr/nr-types-test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "../utest/utest.h"
2
 
#include <libnr/nr-types.h>
3
 
#include <libnr/nr-point-fns.h>
4
 
#include <cmath>
5
 
using NR::Point;
6
 
using NR::X;
7
 
using NR::Y;
8
 
 
9
 
 
10
 
int main(int argc, char *argv[]) {
11
 
        utest_start("Basic NR::Point operations");
12
 
 
13
 
        UTEST_TEST("X,Y values") {
14
 
                UTEST_ASSERT(X == 0);
15
 
                UTEST_ASSERT(Y == 1);
16
 
        }
17
 
 
18
 
        NR::Point const a(1.5, 2.0);
19
 
        UTEST_TEST("x,y constructor and operator[] const") {
20
 
                UTEST_ASSERT(a[X] == 1.5);
21
 
                UTEST_ASSERT(a[Y] == 2.0);
22
 
        }
23
 
 
24
 
        NR::Point const b(-2.0, 3.0);
25
 
 
26
 
        UTEST_TEST("copy constructor") {
27
 
                NR::Point a_copy(a);
28
 
                UTEST_ASSERT(a == a_copy);
29
 
                UTEST_ASSERT(!(a != a_copy));
30
 
        }
31
 
 
32
 
        UTEST_TEST("non-const operator[]") {
33
 
                NR::Point a_copy(a);
34
 
                a_copy[X] = -2.0;
35
 
                UTEST_ASSERT(a_copy != a);
36
 
                UTEST_ASSERT(a_copy != b);
37
 
                a_copy[Y] = 3.0;
38
 
                UTEST_ASSERT(a_copy == b);
39
 
        }
40
 
 
41
 
        NR::Point const ab(-0.5, 5.0);
42
 
        UTEST_TEST("binary +, -") {
43
 
                UTEST_ASSERT(a != b);
44
 
                UTEST_ASSERT(a + b == ab);
45
 
                UTEST_ASSERT(ab - a == b);
46
 
                UTEST_ASSERT(ab - b == a);
47
 
                UTEST_ASSERT(ab + a != b);
48
 
        }
49
 
 
50
 
        UTEST_TEST("unary-") {
51
 
                UTEST_ASSERT(-a == Point(-a[X], -a[Y]));
52
 
        }
53
 
 
54
 
        UTEST_TEST("scale, divide") {
55
 
                UTEST_ASSERT(-a == -1.0 * a);
56
 
                UTEST_ASSERT(a + a + a == 3.0 * a);
57
 
                UTEST_ASSERT(a / .5 == 2.0 * a);
58
 
        }
59
 
 
60
 
        UTEST_TEST("dot") {
61
 
                UTEST_ASSERT( dot(a, b) == ( a[X] * b[X]  +
62
 
                                             a[Y] * b[Y] ) );
63
 
                UTEST_ASSERT( dot(a, NR::rot90(a)) == 0.0 );
64
 
                UTEST_ASSERT( dot(-a, NR::rot90(a)) == 0.0 );
65
 
        }
66
 
 
67
 
        double const small = pow(2.0, -1070);
68
 
 
69
 
        Point const small_left(-small, 0.0);
70
 
        Point const smallish_3_neg4(3.0 * small, -4.0 * small);
71
 
 
72
 
        UTEST_TEST("L1, L2, LInfty norms") {
73
 
                UTEST_ASSERT(L1(small_left) == small);
74
 
                UTEST_ASSERT(L2(small_left) == small);
75
 
                UTEST_ASSERT(LInfty(small_left) == small);
76
 
 
77
 
                UTEST_ASSERT(L1(smallish_3_neg4) == 7.0 * small);
78
 
                UTEST_ASSERT(L2(smallish_3_neg4) == 5.0 * small);
79
 
                UTEST_ASSERT(LInfty(smallish_3_neg4) == 4.0 * small);
80
 
        }
81
 
 
82
 
        UTEST_TEST("operator+=") {
83
 
                Point x(a);
84
 
                x += b;
85
 
                UTEST_ASSERT(x == ab);
86
 
        }
87
 
 
88
 
        UTEST_TEST("operator/=") {
89
 
                Point x(a);
90
 
                x /= .5;
91
 
                UTEST_ASSERT(x == a + a);
92
 
        }
93
 
 
94
 
        UTEST_TEST("normalize") {
95
 
                Point x(small_left);
96
 
                x.normalize();
97
 
                UTEST_ASSERT(x == Point(-1.0, 0.0));
98
 
 
99
 
                x = smallish_3_neg4;
100
 
                x.normalize();
101
 
                UTEST_ASSERT(x == Point(0.6, -0.8));
102
 
        }
103
 
 
104
 
        return utest_end() ? 0 : 1;
105
 
}