1 #include <utest/utest.h>
2 #include <libnr/nr-scale.h>
3 #include <libnr/nr-scale-ops.h>
4 using NR::X;
5 using NR::Y;
7 int main(int argc, char *argv[])
8 {
9 utest_start("NR::scale");
11 NR::scale const sa(1.5, 2.0);
12 UTEST_TEST("x,y constructor and operator[] const") {
13 UTEST_ASSERT(sa[X] == 1.5);
14 UTEST_ASSERT(sa[Y] == 2.0);
15 UTEST_ASSERT(sa[0u] == 1.5);
16 UTEST_ASSERT(sa[1u] == 2.0);
17 }
19 NR::Point const b(-2.0, 3.0);
20 NR::scale const sb(b);
22 UTEST_TEST("copy constructor, operator==, operator!=") {
23 NR::scale const sa_copy(sa);
24 UTEST_ASSERT( sa == sa_copy );
25 UTEST_ASSERT(!( sa != sa_copy ));
26 UTEST_ASSERT( sa != sb );
27 }
29 UTEST_TEST("operator=") {
30 NR::scale sa_eq(sb);
31 sa_eq = sa;
32 UTEST_ASSERT( sa == sa_eq );
33 }
35 UTEST_TEST("point constructor") {
36 UTEST_ASSERT(sb[X] == b[X]);
37 UTEST_ASSERT(sb[Y] == b[Y]);
38 }
40 UTEST_TEST("operator*(Point, scale)") {
41 NR::Point const ab( b * sa );
42 UTEST_ASSERT( ab == NR::Point(-3.0, 6.0) );
43 }
45 UTEST_TEST("operator*(scale, scale)") {
46 NR::scale const sab( sa * sb );
47 UTEST_ASSERT( sab == NR::scale(-3.0, 6.0) );
48 }
50 UTEST_TEST("operator/(scale, scale)") {
51 NR::scale const sa_b( sa / sb );
52 NR::scale const exp_sa_b(-0.75, 2./3.);
53 UTEST_ASSERT( sa_b[0] == exp_sa_b[0] );
54 UTEST_ASSERT( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 );
55 }
57 return ( utest_end()
58 ? EXIT_SUCCESS
59 : EXIT_FAILURE );
60 }
62 /*
63 Local Variables:
64 mode:c++
65 c-file-style:"stroustrup"
66 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
67 indent-tabs-mode:nil
68 fill-column:99
69 End:
70 */
71 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :