00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <base/BaseTest>
00026
00027 #include <base/array>
00028 #include <base/Math>
00029 #include <base/Transform>
00030
00031
00032 using base::BaseTest;
00033
00034 using base::array;
00035 using base::Math;
00036 using base::Transform;
00037 using base::inverse;
00038
00039
00040
00041 BaseTest::BaseTest()
00042 {
00043 }
00044
00045
00046 void BaseTest::setUp()
00047 {
00048
00049 }
00050
00051
00052 void BaseTest::tearDown()
00053 {
00054 }
00055
00056
00057
00058 void BaseTest::testarray()
00059 {
00060 array<int> a0;
00061 CPPUNIT_ASSERT(a0.size() == 0);
00062
00063 array<int> a1(1);
00064 a1[0]=0;
00065 CPPUNIT_ASSERT(a1.size() == 1);
00066 CPPUNIT_ASSERT(a1[0] == 0);
00067
00068 array<int> a2(2,6);
00069 CPPUNIT_ASSERT(a2.size() == 2);
00070 CPPUNIT_ASSERT(a2.capacity() == 6);
00071
00072
00073 a2[0]=a2[1]=-1;
00074 a1 = a2;
00075 CPPUNIT_ASSERT(a1.size() == 2);
00076 CPPUNIT_ASSERT(a1[0] == -1);
00077 CPPUNIT_ASSERT(a1[1] == -1);
00078
00079
00080 a1.at(3) = -4;
00081 CPPUNIT_ASSERT(a1.size() == 4);
00082 CPPUNIT_ASSERT(a1[3] == -4);
00083
00084
00085 a1.swap(a2);
00086 CPPUNIT_ASSERT(a1.size() == 2);
00087 CPPUNIT_ASSERT(a1[0] == -1);
00088 a1[0] = 1;
00089
00090
00091 a1.resize(10);
00092 CPPUNIT_ASSERT(a1.size() == 10);
00093 a1[9] = 9;
00094 CPPUNIT_ASSERT(a1[0] == 1);
00095 CPPUNIT_ASSERT(a1[9] == 9);
00096
00097
00098 a1.clear();
00099 CPPUNIT_ASSERT(a1.size() == 0);
00100 CPPUNIT_ASSERT(a1.empty());
00101
00102
00103 a1 = a2;
00104 CPPUNIT_ASSERT( a1 == a2 );
00105 a1.at(a1.size()) = -2;
00106 CPPUNIT_ASSERT( a1 != a2 );
00107
00108
00109 a1 = array<int>(0,2);
00110 for(int i=0; i<32; i++)
00111 a1.push_back(i);
00112
00113 CPPUNIT_ASSERT( a1.size() == 32 );
00114 for(int i=0; i<32; i++)
00115 CPPUNIT_ASSERT( a1[i] == i );
00116
00117
00118 a2.resize(1);
00119 a2[0] = 5;
00120 CPPUNIT_ASSERT( a2.size() == 1 );
00121 CPPUNIT_ASSERT( (*a2.begin()) == 5 );
00122
00123 array<int>::const_iterator i = a1.begin();
00124 array<int>::const_iterator e = a1.end();
00125 int c=0;
00126 while (i != e) {
00127 CPPUNIT_ASSERT( (*i) == c );
00128 ++i; ++c;
00129 }
00130
00131 }
00132
00133
00134
00135
00136 void BaseTest::testTransform()
00137 {
00138
00139 Transform ti;
00140 CPPUNIT_ASSERT( ti.identity() );
00141 CPPUNIT_ASSERT( ti.isTransRotationOnly() );
00142 CPPUNIT_ASSERT( !ti.containsRotation() );
00143 CPPUNIT_ASSERT( !ti.containsTranslation() );
00144
00145 Quat4 q1( Vector3(1,2,3), consts::Pi/3.0 );
00146 Transform r1(q1);
00147
00148
00149 CPPUNIT_ASSERT( !r1.containsTranslation() );
00150 CPPUNIT_ASSERT( r1.containsRotation() );
00151 CPPUNIT_ASSERT( !r1.identity() );
00152 CPPUNIT_ASSERT( r1.isTransRotationOnly() );
00153
00154 Quat4 q2(Vector3(1,2,1), consts::Pi/4.0);
00155 Transform r2(q2);
00156
00157
00158 Transform r3( r1*r2 );
00159
00160 Matrix3 m1 = Orient(q1);
00161 Matrix3 m2 = Orient(q2);
00162
00163 Matrix3 m3( m1*m2 );
00164
00165 CPPUNIT_ASSERT( Matrix4(m3,Point3()).equals( r3.getTransform() ) );
00166 CPPUNIT_ASSERT( Orient(m3).equals( r3.getRotation() ) );
00167
00168 Matrix3 m3i( inverse(m3) );
00169 Transform r3i( inverse(r3) );
00170
00171 CPPUNIT_ASSERT( Matrix4(m3i,Point3()).equals( r3i.getTransform() ) );
00172 CPPUNIT_ASSERT( Orient(m3i).equals( r3i.getRotation() ) );
00173
00174 Transform ti2( r3*r3i );
00175 CPPUNIT_ASSERT( ti2.equals(ti) );
00176
00177
00178
00179 Transform t1(Vector3(3,2,4), q1);
00180 CPPUNIT_ASSERT( t1.containsTranslation() );
00181 CPPUNIT_ASSERT( t1.containsRotation() );
00182 CPPUNIT_ASSERT( !t1.identity() );
00183 CPPUNIT_ASSERT( t1.isTransRotationOnly() );
00184
00185 Transform t1i( inverse(t1) );
00186 Transform ti3( t1*t1i );
00187 CPPUNIT_ASSERT( ti3.equals(ti) );
00188
00189
00190 Transform t2(Vector3(2,2,3), q2);
00191 Transform t2i( inverse(t2) );
00192 Transform t2ib( t2i );
00193 t2ib.setRotationComponent( t2ib.getRotation() );
00194 CPPUNIT_ASSERT( t2i.equals(t2ib) );
00195
00196 }
00197
00198
00199
00200 #ifdef DEBUG
00201 CPPUNIT_TEST_SUITE_REGISTRATION( BaseTest );
00202 #endif
00203