ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/test/math/VectorTestCase.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/test/math/VectorTestCase.cpp (file contents):
Revision 1593 by tim, Mon Oct 18 21:03:15 2004 UTC vs.
Revision 1594 by tim, Mon Oct 18 23:13:23 2004 UTC

# Line 5 | Line 5 | void VectorTestCase::setUp(){
5  
6  
7   void VectorTestCase::setUp(){
8 < }
8 >    zero[0] = 0.0;
9 >    zero[1] = 0.0;
10 >    zero[2] = 0.0;
11 >    zero[3] = 0.0;
12  
13 < void VectorTestCase::tearDown(){
13 >    one[0] = 1.0;
14 >    one[1] = 1.0;
15 >    one[2] = 1.0;
16 >    one[3] = 1.0;
17 >
18 >    two[0] = 2.0;
19 >    two[1] = 2.0;
20 >    two[2] = 2.0;
21 >    two[3] = 2.0;
22 >
23 >
24 >    v1[0] = 3.0;
25 >    v1[1] = 0.0;
26 >    v1[2] = 2.0;
27 >    v1[3] = 1.0;        
28 >
29 >    v2[0] = -3.0;
30 >    v2[1] = 0.0;
31 >    v2[2] = -2.0;
32 >    v2[3] = -1.0;        
33 >
34 >    v3[0] = 4.0;
35 >    v3[1] = 1.0;
36 >    v3[2] = 3.0;
37 >    v3[3] = 2.0;        
38 >
39 >    s1 = 1.0;
40 >    s2 = 2.0;
41 >    
42   }
43  
44   void VectorTestCase::testConstructors(){
45 +    Vec4 a0;
46 +    Vec4 a1(1);
47 +    Vec4 a2(2);
48 +    
49 +    CPPUNIT_ASSERT( a0 == zero);
50 +    CPPUNIT_ASSERT( a1 == one);
51 +    CPPUNIT_ASSERT( a2 == two);
52 +
53 +    CPPUNIT_ASSERT( a1 != two);
54 +
55 +    //test copy constructor
56 +    Vec4 b1(v1);
57 +    CPPUNIT_ASSERT( b1 == v1);
58 +
59 +    //test operator =
60 +    b1 = v2;
61 +    CPPUNIT_ASSERT( b1 == v2);
62 +
63 +    //test constructor from an array    
64 +    double tempArray[] = {1.0, 2.0, 5.0, 8.0};
65 +    Vec4 tempV;
66 +    tempV[0] = 1.0;
67 +    tempV[1] = 2.0;
68 +    tempV[2] = 5.0;
69 +    tempV[3] = 8.0;
70 +    
71 +    Vec4 b2(tempV);
72 +    CPPUNIT_ASSERT( b2 == tempArray);
73 +    
74   }
75  
76   void VectorTestCase::testArithmetic(){
77 +    //test negate
78 +    Vec4 a0 = v2;
79 +    a0.negate();
80 +    CPPUNIT_ASSERT (a0 == v1);
81 +    
82 +    Vec4 a1;
83 +    a1.negate(v2);
84 +    CPPUNIT_ASSERT(a1 == v1);
85 +
86 +    //test add
87 +    Vec4 a2;
88 +    a2 = v1;
89 +    a2.add(v2);    
90 +    CPPUNIT_ASSERT( a2 == zero);
91 +
92 +    Vec4 a3;
93 +    a3.add(v2, v3);      
94 +    CPPUNIT_ASSERT( a3 == one);
95 +    
96 +
97 +    //test sub
98 +    Vec4 a4;
99 +    a4 = two;
100 +    a4.sub(one);
101 +    CPPUNIT_ASSERT( a4 == one);    
102 +
103 +    Vec4 a5;
104 +    a5.sub(two, one);
105 +    CPPUNIT_ASSERT( a5 == one);      
106 +    
107 +    //test mul
108 +    Vec4 a6;
109 +    a6 = one;
110 +    a6.mul(2.0);
111 +    CPPUNIT_ASSERT( a6 == two);      
112 +
113 +    Vec4 a7;
114 +    a7.mul(one, 2.0);
115 +    CPPUNIT_ASSERT( a7 == two);      
116 +    Vec4 a8;
117 +    a7.mul(zero, 2.0);
118 +    CPPUNIT_ASSERT( a7 == zero);      
119 +
120 +    //test div
121 +    Vec4 a9;
122 +    a9 = two;
123 +    a9.div(2.0);
124 +    CPPUNIT_ASSERT( a9 == one);      
125 +
126 +    Vec4 a10;
127 +    a10.div(two, 2.0);
128 +    CPPUNIT_ASSERT( a10 == one);      
129 +    Vec4 a11;
130 +    a11.mul(zero, 2.0);
131 +    CPPUNIT_ASSERT( a11 == zero);      
132 +    
133 +    
134   }
135  
136   void VectorTestCase::testOperators(){
137 +    //test unary minus
138 +    Vec4 a0 = v2;
139 +    a0 = - a0;
140 +    CPPUNIT_ASSERT (a0 == v1);
141 +  
142 +
143 +    //test add
144 +    Vec4 a1;
145 +    a1 = v1;
146 +    a1 += v2;
147 +    CPPUNIT_ASSERT( a1 == zero);
148 +
149 +    Vec4 a2;
150 +    a2 = v2 + v3;
151 +    CPPUNIT_ASSERT( a2 == one);
152 +
153 +    //test sub
154 +    Vec4 a3;
155 +    a3 = two;
156 +    a3 -= one;
157 +    CPPUNIT_ASSERT( a3 == one);    
158 +
159 +    Vec4 a4;
160 +    a4 = two - one;
161 +    CPPUNIT_ASSERT( a4 == one);
162 +
163 +    Vec4 a5;
164 +    a5.sub(two, one);
165 +    CPPUNIT_ASSERT( a5 == one);      
166 +    
167 +    //test mul
168 +    Vec4 a6;
169 +    a6 = one;
170 +    a6.mul(2.0);
171 +    CPPUNIT_ASSERT( a6 == two);      
172 +
173 +    Vec4 a7;
174 +    a7.mul(one, 2.0);
175 +    CPPUNIT_ASSERT( a7 == two);      
176 +    Vec4 a8;
177 +    a7.mul(zero, 2.0);
178 +    CPPUNIT_ASSERT( a7 == zero);      
179 +
180 +    //test div
181 +    Vec4 a9;
182 +    a9 = two;
183 +    a9.div(2.0);
184 +    CPPUNIT_ASSERT( a9 == one);      
185 +
186 +    Vec4 a10;
187 +    a10.div(two, 2.0);
188 +    CPPUNIT_ASSERT( a10 == one);      
189 +    Vec4 a11;
190 +    a11.mul(zero, 2.0);
191 +    CPPUNIT_ASSERT( a11 == zero);  
192 +
193   }
194  
195   void VectorTestCase::testAccessEntries(){
196 +    CPPUNIT_ASSERT(zero[0] == 0.0);
197 +    CPPUNIT_ASSERT(one[0] == 1.0);
198 +    CPPUNIT_ASSERT(v3[0] == 4.0);
199 +
200 +    CPPUNIT_ASSERT(v3(0) != 1.0);
201 +
202   }
203  
204   void VectorTestCase::testOtherTemplateFunctions(){        
205  
206 < }
206 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines