ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/test/math/RectMatrixTestCase.cpp
Revision: 1603
Committed: Tue Oct 19 21:28:55 2004 UTC (19 years, 8 months ago) by tim
File size: 6140 byte(s)
Log Message:
more bugs get fixed at math library

File Contents

# Content
1 #include "RectMatrixTestCase.hpp"
2
3 // Registers the fixture into the 'registry'
4 CPPUNIT_TEST_SUITE_REGISTRATION( RectMatrixTestCase );
5
6 void RectMatrixTestCase::setUp(){
7
8 m1(0, 0) = 1.0;
9 m1(0, 1) = 1.0;
10 m1(1, 0) = 3.0;
11 m1(1, 1) = 1.0;
12
13 m2(0, 0) = 1.0;
14 m2(0, 1) = 0.0;
15 m2(1, 0) = 0.0;
16 m2(1, 1) = 1.0;
17
18
19 m3(0, 0) = 1.0;
20 m3(0, 1) = 0.0;
21 m3(1, 0) = 0.0;
22 m3(1, 1) = 1.0;
23
24 m4(0, 0) = -1.0;
25 m4(0, 1) = -1.0;
26 m4(1, 0) = -3.0;
27 m4(1, 1) = -1.0;
28
29 zero(0, 0) = 0.0;
30 zero(0, 1) = 0.0;
31 zero(1, 0) = 0.0;
32 zero(1, 1) = 0.0;
33
34 one(0, 0) = 1.0;
35 one(0, 1) = 1.0;
36 one(1, 0) = 1.0;
37 one(1, 1) = 1.0;
38
39 two(0, 0) = 2.0;
40 two(0, 1) = 2.0;
41 two(1, 0) = 2.0;
42 two(1, 1) = 2.0;
43
44 a(0, 0) = 1.0;
45 a(0, 1) = 0.0;
46 a(0, 2) = 0.0;
47 a(1, 0) = 0.0;
48 a(1, 1) = 1.0;
49 a(1, 2) = 0.0;
50
51 b(0, 0) = 1.0;
52 b(0, 1) = 0.0;
53 b(1, 0) = 0.0;
54 b(1, 1) = 1.0;
55 b(2, 0) = 0.0;
56 b(2, 1) = 0.0;
57
58 c(0, 0) = 1.0;
59 c(0, 1) = 0.0;
60 c(1, 0) = 0.0;
61 c(1, 1) = 1.0;
62
63 d(0, 0) = 1.0;
64 d(0, 1) = 0.0;
65 d(0, 2) = 0.0;
66 d(1, 0) = 0.0;
67 d(1, 1) = 0.0;
68 d(1, 2) = 1.0;
69 d(2, 0) = 0.0;
70 d(2, 1) = 1.0;
71 d(2, 2) = 0.0;
72
73 e(0, 0) = 2.0;
74 e(0, 1) = 4.0;
75 e(0, 2) = 1.0;
76 e(1, 0) = 0.0;
77 e(1, 1) = 0.0;
78 e(1, 2) = 3.0;
79 e(2, 0) = 0.0;
80 e(2, 1) = 6.0;
81 e(2, 2) = 5.0;
82
83 f(0, 0) = 2.0;
84 f(0, 1) = 4.0;
85 f(0, 2) = 1.0;
86 f(1, 0) = 0.0;
87 f(1, 1) = 6.0;
88 f(1, 2) = 5.0;
89 f(2, 0) = 0.0;
90 f(2, 1) = 0.0;
91 f(2, 2) = 3.0;
92
93 f(0, 0) = 2.0;
94 f(0, 1) = 4.0;
95 f(0, 2) = 1.0;
96 f(1, 0) = 0.0;
97 f(1, 1) = 6.0;
98 f(1, 2) = 5.0;
99 f(2, 0) = 0.0;
100 f(2, 1) = 0.0;
101 f(2, 2) = 3.0;
102
103 g(0, 0) = 1.0;
104 g(0, 1) = 0.0;
105 g(0, 2) = 0.0;
106 g(1, 0) = -2.0;
107 g(1, 1) = 1.0;
108 g(1, 2) = 0.0;
109 g(2, 0) = 0.0;
110 g(2, 1) = 0.0;
111 g(2, 2) = 1.0;
112
113 h(0, 0) = 2.0;
114 h(0, 1) = 4.0;
115 h(0, 2) = -2.0;
116 h(0, 3) = 2.0;
117 h(1, 0) = 4.0;
118 h(1, 1) = 9.0;
119 h(1, 2) = -3.0;
120 h(1, 3) = 8.0;
121 h(2, 0) = -2.0;
122 h(2, 1) = -3.0;
123 h(2, 2) = 7.0;
124 h(2, 3) = 10.0;
125
126 i(0, 0) = 2.0;
127 i(0, 1) = 4.0;
128 i(0, 2) = -2.0;
129 i(0, 3) = 2.0;
130 i(1, 0) = 0.0;
131 i(1, 1) = 1.0;
132 i(1, 2) = 1.0;
133 i(1, 3) = 4.0;
134 i(2, 0) = -2.0;
135 i(2, 1) = -3.0;
136 i(2, 2) = 7.0;
137 i(2, 3) = 10.0;
138
139
140 v1(0) = 2.0;
141 v1(1) = 4.0;
142 v1(2) = -2.0;
143
144 v2(0) = 2.0;
145 v2(1) = 0.0;
146 v2(2) = -2.0;
147
148 }
149
150 void RectMatrixTestCase::testConstructor(){
151
152 //test default constructor
153 RMat2x2 tmp1;
154 CPPUNIT_ASSERT(tmp1 == zero);
155
156 //test RectMatrix(Real s)
157 RMat2x2 tmp2;
158 CPPUNIT_ASSERT(tmp2 == zero);
159
160 //test copy constructor
161 RMat2x2 tmp3(m1);
162 CPPUNIT_ASSERT(tmp3 == m1);
163
164 //test copy assignment
165 RMat2x2 tmp4 = m2;
166 tmp4 = tmp4;
167 CPPUNIT_ASSERT(tmp4 == m2);
168
169
170 }
171
172 void RectMatrixTestCase::testEqual() {
173 CPPUNIT_ASSERT(m2 == m3);
174 CPPUNIT_ASSERT(m2 != m3);
175
176 }
177
178 void RectMatrixTestCase::testNegate() {
179
180 CPPUNIT_ASSERT(m1 == -m4);
181 }
182
183 void RectMatrixTestCase::testAdd() {
184 RMat2x2 tmp;
185
186 CPPUNIT_ASSERT(m1 + m4 == zero);
187
188 tmp.add(m1, m1);
189
190 CPPUNIT_ASSERT(m1 * 2.0 == tmp);
191
192 tmp = one;
193 tmp *= 2.0;
194
195 CPPUNIT_ASSERT(tmp == two);
196
197 }
198
199 void RectMatrixTestCase::testSub() {
200
201 RMat2x2 tmp(m2);
202 tmp.sub(m2);
203 CPPUNIT_ASSERT(tmp == zero);
204
205 tmp = m2;
206 tmp -= m2;
207 CPPUNIT_ASSERT(tmp == zero);
208
209 tmp = m1;
210 tmp.sub(m1 , m4);
211 CPPUNIT_ASSERT(tmp == m1 * 2.0);
212
213 CPPUNIT_ASSERT(m1 -m4 == m1 * 2.0);
214
215
216 }
217
218 void RectMatrixTestCase::testMul() {
219
220 CPPUNIT_ASSERT(m1 * 1.0 == m1);
221 CPPUNIT_ASSERT(m1 * 0.0 == zero);
222 CPPUNIT_ASSERT(2.0 *m1 == m1 + m1);
223
224 //test matrix multiplication
225 CPPUNIT_ASSERT(a * b == c);
226 CPPUNIT_ASSERT(d * e == f);
227 CPPUNIT_ASSERT(g * h == i);
228
229 //test matrix vector multiplication
230 CPPUNIT_ASSERT(g * v1 == v2);
231
232 }
233
234 void RectMatrixTestCase::testDiv() {
235
236 CPPUNIT_ASSERT(m1 / 1.0 == m1);
237
238 CPPUNIT_ASSERT(m1 / 2.0 * 2.0 == m1);
239
240
241 }
242
243 void RectMatrixTestCase::testAccessEntries(){
244 CPPUNIT_ASSERT_DOUBLES_EQUAL(m1(1, 0), 3.0, oopse::epsilon);
245 }
246
247 void RectMatrixTestCase::testRowColOperations() {
248 Vec3 row;
249 Vec3 col;
250 RMat3x3 m;
251
252 //test getRow
253 row = e.getRow(0);
254 CPPUNIT_ASSERT_DOUBLES_EQUAL(row[0], 2.0, oopse::epsilon);
255 CPPUNIT_ASSERT_DOUBLES_EQUAL(row[1], 4.0, oopse::epsilon);
256 CPPUNIT_ASSERT_DOUBLES_EQUAL(row[2], 1.0, oopse::epsilon);
257 //test setRow
258 row[0] = 2.0;
259 row[1] = 4.0;
260 row[2] = 1.0;
261 m.setRow(0, row);
262 row[0] = 0.0;
263 row[1] = 0.0;
264 row[2] = 3.0;
265 m.setRow(1, row);
266 row[0] = 0.0;
267 row[1] = 6.0;
268 row[2] = 5.0;
269 m.setRow(2, row);
270 CPPUNIT_ASSERT(m == e);
271
272 //test getCol
273 col = e.getColum(1);
274 CPPUNIT_ASSERT_DOUBLES_EQUAL(col[0], 4.0, oopse::epsilon);
275 CPPUNIT_ASSERT_DOUBLES_EQUAL(col[1], 0.0, oopse::epsilon);
276 CPPUNIT_ASSERT_DOUBLES_EQUAL(col[2], 6.0, oopse::epsilon);
277 //test setCol
278 col[0] = 2.0;
279 col[1] = 0.0;
280 col[2] = 0.0;
281 m.setColum(0, col);
282 col[0] = 4.0;
283 col[1] = 0.0;
284 col[2] = 6.0;
285 m.setColum(1, col);
286 col[0] = 1.0;
287 col[1] = 3.0;
288 col[2] = 5.0;
289 m.setColum(2, col);
290 CPPUNIT_ASSERT(m == e);
291
292 //test swapRow
293 RMat2x3 r;
294 r(0, 0) = 0.0;
295 r(0, 1) = 1.0;
296 r(0, 2) = 0.0;
297 r(1, 0) = 1.0;
298 r(1, 1) = 0.0;
299 r(1, 2) = 0.0;
300 r.swapRow(0, 1);
301 CPPUNIT_ASSERT(r == a);
302
303 //test swapCol
304 RMat3x3 s;
305 s(0, 0) = 4.0;
306 s(0, 1) = 2.0;
307 s(0, 2) = 1.0;
308 s(1, 0) = 0.0;
309 s(1, 1) = 0.0;
310 s(1, 2) = 3.0;
311 s(2, 0) = 6.0;
312 s(2, 1) = 0.0;
313 s(2, 2) = 5.0;
314
315 s.swapColum(0, 1);
316 CPPUNIT_ASSERT(s == e);
317
318 }
319
320 void RectMatrixTestCase::testOtherMemberFunctions(){
321 //test transpose
322 CPPUNIT_ASSERT((a.transpose()).transpose() == a);
323
324 CPPUNIT_ASSERT(a.transpose() == b);
325 }

Properties

Name Value
svn:executable *