summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/Makefile_insert71
-rw-r--r--src/libnr/in-svg-plane-test.cpp58
-rw-r--r--src/libnr/nr-matrix-test.cpp171
-rw-r--r--src/libnr/nr-point-fns-test.cpp107
-rw-r--r--src/libnr/nr-rotate-fns-test.cpp43
-rw-r--r--src/libnr/nr-rotate-test.cpp89
-rw-r--r--src/libnr/nr-scale-test.cpp71
-rw-r--r--src/libnr/nr-translate-test.cpp65
-rw-r--r--src/libnr/nr-types-test.cpp105
9 files changed, 19 insertions, 761 deletions
diff --git a/src/libnr/Makefile_insert b/src/libnr/Makefile_insert
index 21cce1ea2..f77475e6c 100644
--- a/src/libnr/Makefile_insert
+++ b/src/libnr/Makefile_insert
@@ -93,6 +93,7 @@ libnr_libnr_a_SOURCES = \
libnr/nr-values.h \
$(libnr_mmx_sources)
+# Ancient performance test (?)
libnr_testnr_SOURCES = \
libnr/testnr.cpp
@@ -100,63 +101,29 @@ libnr_testnr_LDADD = \
libnr/libnr.a \
-lglib-2.0
-
-libnr/test-nr-main.cpp: libnr/test-nr.cpp
- $(top_srcdir)/cxxtest/cxxtestgen.pl --template=$(srcdir)/selfname.tpl -root -o libnr/test-nr-main.cpp $(libnr_test_nr_includes)
-
-libnr/test-nr.cpp: $(libnr_test_nr_includes)
- $(top_srcdir)/cxxtest/cxxtestgen.pl --have-eh -part -o libnr/test-nr.cpp $(libnr_test_nr_includes)
-
-libnr_test_nr_includes = \
+# ######################
+# ### CxxTest stuff ####
+# ######################
+libnr_testsuites = \
+ $(srcdir)/libnr/in-svg-plane-test.h \
$(srcdir)/libnr/nr-compose-test.h \
- $(srcdir)/libnr/nr-types-test.h \
- $(srcdir)/libnr/nr-translate-test.h \
- $(srcdir)/libnr/nr-rotate-test.h \
- $(srcdir)/libnr/nr-scale-test.h \
+ $(srcdir)/libnr/nr-matrix-test.h \
$(srcdir)/libnr/nr-point-fns-test.h \
+ $(srcdir)/libnr/nr-rotate-test.h \
$(srcdir)/libnr/nr-rotate-fns-test.h \
- $(srcdir)/libnr/in-svg-plane-test.h \
- $(srcdir)/libnr/nr-matrix-test.h
-
-libnr_libtest_nr_a_SOURCES = \
- libnr/test-nr.cpp \
- libnr/nr-compose-reference.cpp \
- libnr/nr-compose-reference.h \
- $(libnr_test_nr_includes)
+ $(srcdir)/libnr/nr-scale-test.h \
+ $(srcdir)/libnr/nr-translate-test.h \
+ $(srcdir)/libnr/nr-types-test.h
libnr_test_nr_SOURCES = \
- libnr/test-nr-main.cpp \
- $(libnr_test_nr_includes)
+ libnr/test-nr.cpp \
+ $(libnr_testsuites)
-libnr_test_nr_LDADD = \
- libnr/libnr.a \
- libnr/libtest-nr.a \
- 2geom/lib2geom.a \
+libnr_test_nr_LDADD = \
+ libnr/libnr.a \
+ libnr/nr-compose-reference.o \
+ 2geom/lib2geom.a \
-lglib-2.0
-# -L/usr/X11R6/lib
-# -lX11
-
-libnr_in_svg_plane_test_SOURCES = libnr/in-svg-plane-test.cpp
-libnr_in_svg_plane_test_LDADD = libnr/libnr.a 2geom/lib2geom.a -lglib-2.0
-
-libnr_nr_types_test_SOURCES = libnr/nr-types-test.cpp
-libnr_nr_types_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_point_fns_test_SOURCES = libnr/nr-point-fns-test.cpp
-libnr_nr_point_fns_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_matrix_test_SOURCES = libnr/nr-matrix-test.cpp
-libnr_nr_matrix_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_rotate_test_SOURCES = libnr/nr-rotate-test.cpp
-libnr_nr_rotate_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_rotate_fns_test_SOURCES = libnr/nr-rotate-fns-test.cpp
-libnr_nr_rotate_fns_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_scale_test_SOURCES = libnr/nr-scale-test.cpp
-libnr_nr_scale_test_LDADD = libnr/libnr.a -lglib-2.0
-
-libnr_nr_translate_test_SOURCES = libnr/nr-translate-test.cpp
-libnr_nr_translate_test_LDADD = libnr/libnr.a -lglib-2.0
+libnr/test-nr.cpp: $(libnr_testsuites) libnr/Makefile_insert $(CXXTEST_TEMPLATE)
+ $(CXXTESTGEN) -o libnr/test-nr.cpp $(libnr_testsuites)
diff --git a/src/libnr/in-svg-plane-test.cpp b/src/libnr/in-svg-plane-test.cpp
deleted file mode 100644
index 112dfaedf..000000000
--- a/src/libnr/in-svg-plane-test.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <glib/gmacros.h>
-#include <cmath>
-
-#include "libnr/in-svg-plane.h"
-#include "utest/utest.h"
-#include "2geom/isnan.h"
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("in-svg-plane.h");
-
- NR::Point const p3n4(3.0, -4.0);
- NR::Point const p0(0.0, 0.0);
- double const small = pow(2.0, -1070);
- double const inf = 1e400;
- double const nan = inf - inf;
-
- NR::Point const small_left(-small, 0.0);
- NR::Point const small_n3_4(-3.0 * small, 4.0 * small);
- NR::Point const part_nan(3., nan);
-
- assert(IS_NAN(nan));
- assert(!IS_NAN(small));
-
- UTEST_TEST("in_svg_plane") {
- UTEST_ASSERT(in_svg_plane(p3n4));
- UTEST_ASSERT(in_svg_plane(p0));
- UTEST_ASSERT(in_svg_plane(small_left));
- UTEST_ASSERT(in_svg_plane(small_n3_4));
- UTEST_ASSERT(nan != nan);
- UTEST_ASSERT(!in_svg_plane(NR::Point(nan, 3.)));
- UTEST_ASSERT(!in_svg_plane(NR::Point(inf, nan)));
- UTEST_ASSERT(!in_svg_plane(NR::Point(0., -inf)));
- double const xs[] = {inf, -inf, nan, 1., -2., small, -small};
- for (unsigned i = 0; i < G_N_ELEMENTS(xs); ++i) {
- for (unsigned j = 0; j < G_N_ELEMENTS(xs); ++j) {
- UTEST_ASSERT( in_svg_plane(NR::Point(xs[i], xs[j]))
- == (fabs(xs[i]) < inf &&
- fabs(xs[j]) < inf ) );
- }
- }
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-matrix-test.cpp b/src/libnr/nr-matrix-test.cpp
deleted file mode 100644
index 610ebb750..000000000
--- a/src/libnr/nr-matrix-test.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-#include <utest/utest.h>
-#include <libnr/nr-matrix.h>
-#include <libnr/nr-matrix-fns.h>
-#include <libnr/nr-matrix-ops.h>
-#include <libnr/nr-matrix-rotate-ops.h>
-#include <libnr/nr-matrix-scale-ops.h>
-#include <libnr/nr-point-matrix-ops.h>
-#include <libnr/nr-rotate.h>
-#include <libnr/nr-rotate-ops.h>
-#include <libnr/nr-scale-ops.h>
-#include <libnr/nr-scale-translate-ops.h>
-#include <libnr/nr-translate.h>
-#include <libnr/nr-translate-ops.h>
-#include <libnr/nr-translate-scale-ops.h>
-using NR::Matrix;
-using NR::X;
-using NR::Y;
-
-inline bool point_equalp(NR::Point const &a, NR::Point const &b)
-{
- return ( NR_DF_TEST_CLOSE(a[X], b[X], 1e-5) &&
- NR_DF_TEST_CLOSE(a[Y], b[Y], 1e-5) );
-}
-
-int main(int /*argc*/, char */*argv*/[])
-{
- int rc = EXIT_SUCCESS;
-
- Matrix const m_id(NR::identity());
- NR::rotate const r_id(NR::Point(1, 0));
- NR::translate const t_id(0, 0);
-
- utest_start("Matrix");
-
- Matrix const c16(1.0, 2.0,
- 3.0, 4.0,
- 5.0, 6.0);
- UTEST_TEST("basic constructors, operator=") {
- Matrix const c16_copy(c16);
- Matrix c16_eq(m_id);
- c16_eq = c16;
- for(unsigned i = 0; i < 6; ++i) {
- UTEST_ASSERT( c16[i] == 1.0 + i );
- UTEST_ASSERT( c16[i] == c16_copy[i] );
- UTEST_ASSERT( c16[i] == c16_eq[i] );
- UTEST_ASSERT( m_id[i] == double( i == 0 || i == 3 ) );
- }
- }
-
- UTEST_TEST("scale constructor") {
- NR::scale const s(2.0, 3.0);
- NR::Matrix const ms(s);
- NR::Point const p(5.0, 7.0);
- UTEST_ASSERT( p * s == NR::Point(10.0, 21.0) );
- UTEST_ASSERT( p * ms == NR::Point(10.0, 21.0) );
- }
-
- NR::rotate const r86(NR::Point(.8, .6));
- NR::Matrix const mr86(r86);
- UTEST_TEST("rotate constructor") {
- NR::Point const p0(1.0, 0.0);
- NR::Point const p90(0.0, 1.0);
- UTEST_ASSERT( p0 * r86 == NR::Point(.8, .6) );
- UTEST_ASSERT( p0 * mr86 == NR::Point(.8, .6) );
- UTEST_ASSERT( p90 * r86 == NR::Point(-.6, .8) );
- UTEST_ASSERT( p90 * mr86 == NR::Point(-.6, .8) );
- UTEST_ASSERT(matrix_equalp(Matrix( r86 * r86 ),
- mr86 * mr86,
- 1e-14));
- }
-
- NR::translate const t23(2.0, 3.0);
- UTEST_TEST("translate constructor") {
- NR::Matrix const mt23(t23);
- NR::Point const b(-2.0, 3.0);
- UTEST_ASSERT( b * t23 == b * mt23 );
- }
-
- NR::scale const s_id(1.0, 1.0);
- UTEST_TEST("test_identity") {
- UTEST_ASSERT(m_id.test_identity());
- UTEST_ASSERT(Matrix(t_id).test_identity());
- UTEST_ASSERT(!(Matrix(NR::translate(-2, 3)).test_identity()));
- UTEST_ASSERT(Matrix(r_id).test_identity());
- NR::rotate const rot180(NR::Point(-1, 0));
- UTEST_ASSERT(!(Matrix(rot180).test_identity()));
- UTEST_ASSERT(Matrix(s_id).test_identity());
- UTEST_ASSERT(!(Matrix(NR::scale(1.0, 0.0)).test_identity()));
- UTEST_ASSERT(!(Matrix(NR::scale(0.0, 1.0)).test_identity()));
- UTEST_ASSERT(!(Matrix(NR::scale(1.0, -1.0)).test_identity()));
- UTEST_ASSERT(!(Matrix(NR::scale(-1.0, -1.0)).test_identity()));
- }
-
- UTEST_TEST("inverse") {
- UTEST_ASSERT( m_id.inverse() == m_id );
- UTEST_ASSERT( Matrix(t23).inverse() == Matrix(NR::translate(-2.0, -3.0)) );
- NR::scale const s2(-4.0, 2.0);
- NR::scale const sp5(-.25, .5);
- UTEST_ASSERT( Matrix(s2).inverse() == Matrix(sp5) );
- UTEST_ASSERT( Matrix(sp5).inverse() == Matrix(s2) );
- }
-
- UTEST_TEST("elliptic quadratic form") {
- NR::Matrix const aff(1.0, 1.0,
- 0.0, 1.0,
- 5.0, 6.0);
- NR::Matrix const invaff = aff.inverse();
- UTEST_ASSERT( invaff[1] == -1.0 );
-
- NR::Matrix const ef(elliptic_quadratic_form(invaff));
- NR::Matrix const exp_ef(2, -1,
- -1, 1,
- 0, 0);
- UTEST_ASSERT( ef == exp_ef );
- }
-
- UTEST_TEST("Matrix * rotate") {
- NR::Matrix const ma(2.0, -1.0,
- 4.0, 4.0,
- -0.5, 2.0);
- NR::Matrix const a_r86( ma * r86 );
- NR::Matrix const ma1( a_r86 * r86.inverse() );
- UTEST_ASSERT(matrix_equalp(ma1, ma, 1e-12));
- NR::Matrix const exp_a_r86( 2*.8 + -1*-.6, 2*.6 + -1*.8,
- 4*.8 + 4*-.6, 4*.6 + 4*.8,
- -.5*.8 + 2*-.6, -.5*.6 + 2*.8 );
- UTEST_ASSERT(matrix_equalp(a_r86, exp_a_r86, 1e-12));
- }
-
- UTEST_TEST("translate*scale, scale*translate") {
- NR::translate const t2n4(2, -4);
- NR::scale const sn2_8(-2, 8);
- NR::Matrix const exp_ts(-2, 0,
- 0, 8,
- -4, -32);
- NR::Matrix const exp_st(-2, 0,
- 0, 8,
- 2, -4);
- UTEST_ASSERT( exp_ts == t2n4 * sn2_8 );
- UTEST_ASSERT( exp_st == sn2_8 * t2n4 );
- }
-
- UTEST_TEST("Matrix * scale") {
- NR::Matrix const ma(2.0, -1.0,
- 4.0, 4.0,
- -0.5, 2.0);
- NR::scale const sn2_8(-2, 8);
- NR::Matrix const exp_as(-4, -8,
- -8, 32,
- 1, 16);
- UTEST_ASSERT( ma * sn2_8 == exp_as );
- }
-
- if (!utest_end()) {
- rc = EXIT_FAILURE;
- }
-
- return rc;
-}
-
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-point-fns-test.cpp b/src/libnr/nr-point-fns-test.cpp
deleted file mode 100644
index 0ceb19ac0..000000000
--- a/src/libnr/nr-point-fns-test.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <cassert>
-#include <cmath>
-#include <glib/gmacros.h>
-#include <stdlib.h>
-
-#include "utest/utest.h"
-#include "libnr/nr-point-fns.h"
-#include "2geom/isnan.h"
-
-using NR::Point;
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("nr-point-fns");
-
- Point const p3n4(3.0, -4.0);
- Point const p0(0.0, 0.0);
- double const small = pow(2.0, -1070);
- double const inf = 1e400;
- double const nan = inf - inf;
-
- Point const small_left(-small, 0.0);
- Point const small_n3_4(-3.0 * small, 4.0 * small);
- Point const part_nan(3., nan);
- Point const inf_left(-inf, 5.0);
-
- assert(IS_NAN(nan));
- assert(!IS_NAN(small));
-
- UTEST_TEST("L1") {
- UTEST_ASSERT( NR::L1(p0) == 0.0 );
- UTEST_ASSERT( NR::L1(p3n4) == 7.0 );
- UTEST_ASSERT( NR::L1(small_left) == small );
- UTEST_ASSERT( NR::L1(inf_left) == inf );
- UTEST_ASSERT( NR::L1(small_n3_4) == 7.0 * small );
- UTEST_ASSERT(IS_NAN(NR::L1(part_nan)));
- }
-
- UTEST_TEST("L2") {
- UTEST_ASSERT( NR::L2(p0) == 0.0 );
- UTEST_ASSERT( NR::L2(p3n4) == 5.0 );
- UTEST_ASSERT( NR::L2(small_left) == small );
- UTEST_ASSERT( NR::L2(inf_left) == inf );
- UTEST_ASSERT( NR::L2(small_n3_4) == 5.0 * small );
- UTEST_ASSERT(IS_NAN(NR::L2(part_nan)));
- }
-
- UTEST_TEST("LInfty") {
- UTEST_ASSERT( NR::LInfty(p0) == 0.0 );
- UTEST_ASSERT( NR::LInfty(p3n4) == 4.0 );
- UTEST_ASSERT( NR::LInfty(small_left) == small );
- UTEST_ASSERT( NR::LInfty(inf_left) == inf );
- UTEST_ASSERT( NR::LInfty(small_n3_4) == 4.0 * small );
- UTEST_ASSERT(IS_NAN(NR::LInfty(part_nan)));
- }
-
- UTEST_TEST("is_zero") {
- UTEST_ASSERT(NR::is_zero(p0));
- UTEST_ASSERT(!NR::is_zero(p3n4));
- UTEST_ASSERT(!NR::is_zero(small_left));
- UTEST_ASSERT(!NR::is_zero(inf_left));
- UTEST_ASSERT(!NR::is_zero(small_n3_4));
- UTEST_ASSERT(!NR::is_zero(part_nan));
- }
-
- UTEST_TEST("atan2") {
- UTEST_ASSERT( NR::atan2(p3n4) == atan2(-4.0, 3.0) );
- UTEST_ASSERT( NR::atan2(small_left) == atan2(0.0, -1.0) );
- UTEST_ASSERT( NR::atan2(small_n3_4) == atan2(4.0, -3.0) );
- }
-
- UTEST_TEST("unit_vector") {
- UTEST_ASSERT( NR::unit_vector(p3n4) == Point(.6, -0.8) );
- UTEST_ASSERT( NR::unit_vector(small_left) == Point(-1.0, 0.0) );
- UTEST_ASSERT( NR::unit_vector(small_n3_4) == Point(-.6, 0.8) );
- }
-
- UTEST_TEST("is_unit_vector") {
- UTEST_ASSERT(!NR::is_unit_vector(p3n4));
- UTEST_ASSERT(!NR::is_unit_vector(small_left));
- UTEST_ASSERT(!NR::is_unit_vector(small_n3_4));
- UTEST_ASSERT(!NR::is_unit_vector(part_nan));
- UTEST_ASSERT(!NR::is_unit_vector(inf_left));
- UTEST_ASSERT(!NR::is_unit_vector(Point(.5, 0.5)));
- UTEST_ASSERT(NR::is_unit_vector(Point(.6, -0.8)));
- UTEST_ASSERT(NR::is_unit_vector(Point(-.6, 0.8)));
- UTEST_ASSERT(NR::is_unit_vector(Point(-1.0, 0.0)));
- UTEST_ASSERT(NR::is_unit_vector(Point(1.0, 0.0)));
- UTEST_ASSERT(NR::is_unit_vector(Point(0.0, -1.0)));
- UTEST_ASSERT(NR::is_unit_vector(Point(0.0, 1.0)));
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-rotate-fns-test.cpp b/src/libnr/nr-rotate-fns-test.cpp
deleted file mode 100644
index fb7df7eef..000000000
--- a/src/libnr/nr-rotate-fns-test.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <cmath>
-#include <glib/gmacros.h>
-
-#include <libnr/nr-rotate-fns.h>
-#include <utest/utest.h>
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("rotate-fns");
-
- UTEST_TEST("rotate_degrees") {
- double const d[] = {
- 0, 90, 180, 270, 360, 45, 45.01, 44.99, 134, 135, 136, 314, 315, 317, 359, 361
- };
- for (unsigned i = 0; i < G_N_ELEMENTS(d); ++i) {
- double const degrees = d[i];
- NR::rotate const rot(rotate_degrees(degrees));
- NR::rotate const rot_approx( M_PI * ( degrees / 180. ) );
- UTEST_ASSERT(rotate_equalp(rot, rot_approx, 1e-12));
-
- NR::rotate const rot_inv(rotate_degrees(-degrees));
- NR::rotate const rot_compl(rotate_degrees(360 - degrees));
- UTEST_ASSERT(rotate_equalp(rot_inv, rot_compl, 1e-12));
-
- UTEST_ASSERT(!rotate_equalp(rot, rotate_degrees(degrees + 1), 1e-5));
- }
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/libnr/nr-rotate-test.cpp b/src/libnr/nr-rotate-test.cpp
deleted file mode 100644
index b44562500..000000000
--- a/src/libnr/nr-rotate-test.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-#include <cmath>
-#include <utest/utest.h>
-#include <libnr/nr-matrix.h>
-#include <libnr/nr-matrix-fns.h> /* identity, matrix_equalp */
-#include <libnr/nr-matrix-ops.h>
-#include <libnr/nr-point-fns.h>
-#include <libnr/nr-point-matrix-ops.h>
-#include <libnr/nr-rotate.h>
-#include <libnr/nr-rotate-fns.h>
-#include <libnr/nr-rotate-ops.h>
-using NR::X;
-using NR::Y;
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("rotate");
-
- NR::Matrix const m_id(NR::identity());
- NR::rotate const r_id(0.0);
- NR::rotate const rot234(.234);
- UTEST_TEST("constructors, comparisons") {
- UTEST_ASSERT( r_id == r_id );
- UTEST_ASSERT( rot234 == rot234 );
- UTEST_ASSERT( rot234 != r_id );
- UTEST_ASSERT( r_id == NR::rotate(NR::Point(1.0, 0.0)) );
- UTEST_ASSERT( NR::Matrix(r_id) == m_id );
- UTEST_ASSERT( NR::Matrix(r_id).test_identity() );
-
- UTEST_ASSERT(rotate_equalp(rot234, NR::rotate(NR::Point(cos(.234), sin(.234))), 1e-12));
- }
-
- UTEST_TEST("operator=") {
- NR::rotate rot234_eq(r_id);
- rot234_eq = rot234;
- UTEST_ASSERT( rot234 == rot234_eq );
- UTEST_ASSERT( rot234_eq != r_id );
- }
-
- UTEST_TEST("inverse") {
- UTEST_ASSERT( r_id.inverse() == r_id );
- UTEST_ASSERT( rot234.inverse() == NR::rotate(-.234) );
- }
-
- NR::Point const b(-2.0, 3.0);
- NR::rotate const rot180(NR::Point(-1.0, 0.0));
- UTEST_TEST("operator*(Point, rotate)") {
- UTEST_ASSERT( b * r_id == b );
- UTEST_ASSERT( b * rot180 == -b );
- UTEST_ASSERT( b * rot234 == b * NR::Matrix(rot234) );
- UTEST_ASSERT(point_equalp(b * NR::rotate(M_PI / 2),
- NR::rot90(b),
- 1e-14));
- UTEST_ASSERT( b * rotate_degrees(90.) == NR::rot90(b) );
- }
-
- UTEST_TEST("operator*(rotate, rotate)") {
- UTEST_ASSERT( r_id * r_id == r_id );
- UTEST_ASSERT( rot180 * rot180 == r_id );
- UTEST_ASSERT( rot234 * r_id == rot234 );
- UTEST_ASSERT( r_id * rot234 == rot234 );
- UTEST_ASSERT(rotate_equalp(rot234 * rot234.inverse(), r_id, 1e-14));
- UTEST_ASSERT(rotate_equalp(rot234.inverse() * rot234, r_id, 1e-14));
- UTEST_ASSERT(rotate_equalp(( NR::rotate(0.25) * NR::rotate(.5) ),
- NR::rotate(.75),
- 1e-10));
- }
-
- UTEST_TEST("operator/(rotate, rotate)") {
- UTEST_ASSERT( rot234 / r_id == rot234 );
- UTEST_ASSERT( rot234 / rot180 == rot234 * rot180 );
- UTEST_ASSERT(rotate_equalp(rot234 / rot234, r_id, 1e-14));
- UTEST_ASSERT(rotate_equalp(r_id / rot234, rot234.inverse(), 1e-14));
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-scale-test.cpp b/src/libnr/nr-scale-test.cpp
deleted file mode 100644
index 6bc79917d..000000000
--- a/src/libnr/nr-scale-test.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-#include <utest/utest.h>
-#include <libnr/nr-scale.h>
-#include <libnr/nr-scale-ops.h>
-using NR::X;
-using NR::Y;
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("NR::scale");
-
- NR::scale const sa(1.5, 2.0);
- UTEST_TEST("x,y constructor and operator[] const") {
- UTEST_ASSERT(sa[X] == 1.5);
- UTEST_ASSERT(sa[Y] == 2.0);
- UTEST_ASSERT(sa[0u] == 1.5);
- UTEST_ASSERT(sa[1u] == 2.0);
- }
-
- NR::Point const b(-2.0, 3.0);
- NR::scale const sb(b);
-
- UTEST_TEST("copy constructor, operator==, operator!=") {
- NR::scale const sa_copy(sa);
- UTEST_ASSERT( sa == sa_copy );
- UTEST_ASSERT(!( sa != sa_copy ));
- UTEST_ASSERT( sa != sb );
- }
-
- UTEST_TEST("operator=") {
- NR::scale sa_eq(sb);
- sa_eq = sa;
- UTEST_ASSERT( sa == sa_eq );
- }
-
- UTEST_TEST("point constructor") {
- UTEST_ASSERT(sb[X] == b[X]);
- UTEST_ASSERT(sb[Y] == b[Y]);
- }
-
- UTEST_TEST("operator*(Point, scale)") {
- NR::Point const ab( b * sa );
- UTEST_ASSERT( ab == NR::Point(-3.0, 6.0) );
- }
-
- UTEST_TEST("operator*(scale, scale)") {
- NR::scale const sab( sa * sb );
- UTEST_ASSERT( sab == NR::scale(-3.0, 6.0) );
- }
-
- UTEST_TEST("operator/(scale, scale)") {
- NR::scale const sa_b( sa / sb );
- NR::scale const exp_sa_b(-0.75, 2./3.);
- UTEST_ASSERT( sa_b[0] == exp_sa_b[0] );
- UTEST_ASSERT( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 );
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-translate-test.cpp b/src/libnr/nr-translate-test.cpp
deleted file mode 100644
index 7896315c1..000000000
--- a/src/libnr/nr-translate-test.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <utest/utest.h>
-#include <libnr/nr-point-ops.h>
-#include <libnr/nr-matrix.h>
-#include <libnr/nr-matrix-fns.h>
-#include <libnr/nr-matrix-ops.h>
-#include <libnr/nr-point-matrix-ops.h>
-#include <libnr/nr-translate.h>
-#include <libnr/nr-translate-ops.h>
-using NR::X;
-using NR::Y;
-
-
-int main(int /*argc*/, char */*argv*/[])
-{
- utest_start("translate");
-
- NR::Point const b(-2.0, 3.0);
- NR::translate const tb(b);
- NR::translate const tc(-3.0, -2.0);
- UTEST_TEST("constructors, operator[]") {
- UTEST_ASSERT( tc[X] == -3.0 && tc[Y] == -2.0 );
- UTEST_ASSERT( tb[0] == b[X] && tb[1] == b[Y] );
- }
-
- UTEST_TEST("operator=") {
- NR::translate tb_eq(tc);
- tb_eq = tb;
- UTEST_ASSERT( tb == tb_eq );
- UTEST_ASSERT( tb_eq != tc );
- }
-
- NR::translate const tbc( tb * tc );
- UTEST_TEST("operator*(translate, translate)") {
- UTEST_ASSERT( tbc.offset == NR::Point(-5.0, 1.0) );
- UTEST_ASSERT( tbc.offset == ( tc * tb ).offset );
- UTEST_ASSERT( NR::Matrix(tbc) == NR::Matrix(tb) * NR::Matrix(tc) );
- }
-
- UTEST_TEST("operator*(Point, translate)") {
- UTEST_ASSERT( tbc.offset == b * tc );
- UTEST_ASSERT( b * tc == b * NR::Matrix(tc) );
- }
-
- NR::translate const t_id(0.0, 0.0);
- NR::Matrix const m_id(NR::identity());
- UTEST_TEST("identity") {
- UTEST_ASSERT( b * t_id == b );
- UTEST_ASSERT( NR::Matrix(t_id) == m_id );
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/libnr/nr-types-test.cpp b/src/libnr/nr-types-test.cpp
deleted file mode 100644
index 153ca7910..000000000
--- a/src/libnr/nr-types-test.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-#include "../utest/utest.h"
-#include <libnr/nr-types.h>
-#include <libnr/nr-point-fns.h>
-#include <cmath>
-using NR::Point;
-using NR::X;
-using NR::Y;
-
-
-int main(int /*argc*/, char */*argv*/[]) {
- utest_start("Basic NR::Point operations");
-
- UTEST_TEST("X,Y values") {
- UTEST_ASSERT(X == 0);
- UTEST_ASSERT(Y == 1);
- }
-
- NR::Point const a(1.5, 2.0);
- UTEST_TEST("x,y constructor and operator[] const") {
- UTEST_ASSERT(a[X] == 1.5);
- UTEST_ASSERT(a[Y] == 2.0);
- }
-
- NR::Point const b(-2.0, 3.0);
-
- UTEST_TEST("copy constructor") {
- NR::Point a_copy(a);
- UTEST_ASSERT(a == a_copy);
- UTEST_ASSERT(!(a != a_copy));
- }
-
- UTEST_TEST("non-const operator[]") {
- NR::Point a_copy(a);
- a_copy[X] = -2.0;
- UTEST_ASSERT(a_copy != a);
- UTEST_ASSERT(a_copy != b);
- a_copy[Y] = 3.0;
- UTEST_ASSERT(a_copy == b);
- }
-
- NR::Point const ab(-0.5, 5.0);
- UTEST_TEST("binary +, -") {
- UTEST_ASSERT(a != b);
- UTEST_ASSERT(a + b == ab);
- UTEST_ASSERT(ab - a == b);
- UTEST_ASSERT(ab - b == a);
- UTEST_ASSERT(ab + a != b);
- }
-
- UTEST_TEST("unary-") {
- UTEST_ASSERT(-a == Point(-a[X], -a[Y]));
- }
-
- UTEST_TEST("scale, divide") {
- UTEST_ASSERT(-a == -1.0 * a);
- UTEST_ASSERT(a + a + a == 3.0 * a);
- UTEST_ASSERT(a / .5 == 2.0 * a);
- }
-
- UTEST_TEST("dot") {
- UTEST_ASSERT( dot(a, b) == ( a[X] * b[X] +
- a[Y] * b[Y] ) );
- UTEST_ASSERT( dot(a, NR::rot90(a)) == 0.0 );
- UTEST_ASSERT( dot(-a, NR::rot90(a)) == 0.0 );
- }
-
- double const small = pow(2.0, -1070);
-
- Point const small_left(-small, 0.0);
- Point const smallish_3_neg4(3.0 * small, -4.0 * small);
-
- UTEST_TEST("L1, L2, LInfty norms") {
- UTEST_ASSERT(L1(small_left) == small);
- UTEST_ASSERT(L2(small_left) == small);
- UTEST_ASSERT(LInfty(small_left) == small);
-
- UTEST_ASSERT(L1(smallish_3_neg4) == 7.0 * small);
- UTEST_ASSERT(L2(smallish_3_neg4) == 5.0 * small);
- UTEST_ASSERT(LInfty(smallish_3_neg4) == 4.0 * small);
- }
-
- UTEST_TEST("operator+=") {
- Point x(a);
- x += b;
- UTEST_ASSERT(x == ab);
- }
-
- UTEST_TEST("operator/=") {
- Point x(a);
- x /= .5;
- UTEST_ASSERT(x == a + a);
- }
-
- UTEST_TEST("normalize") {
- Point x(small_left);
- x.normalize();
- UTEST_ASSERT(x == Point(-1.0, 0.0));
-
- x = smallish_3_neg4;
- x.normalize();
- UTEST_ASSERT(x == Point(0.6, -0.8));
- }
-
- return utest_end() ? 0 : 1;
-}