nr-scale-test.h revision c0092c87b724182672defa4f5f75a82c27f017dc
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm#include <cxxtest/TestSuite.h>
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm#include <libnr/nr-scale.h>
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm#include <libnr/nr-scale-ops.h>
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmclass NrScaleTest : public CxxTest::TestSuite
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm{
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmpublic:
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NrScaleTest() :
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm sa( 1.5, 2.0 ),
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm b( -2.0, 3.0 ),
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm sb( b )
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm virtual ~NrScaleTest() {}
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm// createSuite and destroySuite get us per-suite setup and teardown
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm// without us having to worry about static initialization order, etc.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm static NrScaleTest *createSuite() { return new NrScaleTest(); }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm static void destroySuite( NrScaleTest *suite ) { delete suite; }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const sa;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::Point const b;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const sb;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void testXY_CtorArrayOperator(void)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa[NR::X], 1.5 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa[NR::Y], 2.0 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa[0u], 1.5 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa[1u], 2.0 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void testCopyCtor_AssignmentOp_NotEquals(void)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const sa_copy(sa);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa, sa_copy );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT(!( sa != sa_copy ));
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT( sa != sb );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void testAssignmentOp(void)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale sa_eq(sb);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm sa_eq = sa;
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa, sa_eq );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b void testPointCtor(void)
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b {
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b TS_ASSERT_EQUALS( sb[NR::X], b[NR::X] );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sb[NR::Y], b[NR::Y] );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void testOpStarPointScale(void)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::Point const ab( b * sa );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( ab, NR::Point(-3.0, 6.0) );
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b void testOpStarScaleScale(void)
963f23115db07f460bdd862b957f8bd9dba88b9bgustav_b {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const sab( sa * sb );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sab, NR::scale(-3.0, 6.0) );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm void testOpDivScaleScale(void)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm {
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const sa_b( sa / sb );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm NR::scale const exp_sa_b(-0.75, 2./3.);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_EQUALS( sa_b[0], exp_sa_b[0] );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm// TS_ASSERT_EQUALS( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm TS_ASSERT_DELTA( sa_b[1], exp_sa_b[1], 1e-10 );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm }
b4998608f5fbde14c744b6ab8020664300e11f80jucablues};
b4998608f5fbde14c744b6ab8020664300e11f80jucablues
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/*
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm Local Variables:
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm mode:c++
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm c-file-style:"stroustrup"
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm indent-tabs-mode:nil
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen fill-column:99
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen End:
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm*/
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm