view src/main.cpp @ 7:378862555189

Refactored Vectors into templated classes. Much nicer now.
author Eris Caffee <discordia@eldalin.com>
date Wed, 28 Sep 2011 12:48:42 -0500
parents 11e216148d1c
children 81d2aa42a860
line source
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 #include <string>
5 using namespace std;
7 #include "Math.h"
8 using namespace arda;
10 ////////////////////////////////////////////////////////////////////////////////
11 void test_vector(void)
12 {
13 string s1, s2;
15 {
16 cout << "===============================================================" << endl <<
17 "Testing Vector constructors" << endl;
18 Vector2i v2i_1;
19 Vector2i v2i_2(1);
20 Vector2i v2i_3(1, 2);
21 Vector2i v2i_4(v2i_3);
23 cout << setw(40) << "v2i_1: " << v2i_1.getstring(s1) << endl;
24 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
25 cout << setw(40) << "v2i_3: " << v2i_3.getstring(s1) << endl;
26 cout << setw(40) << "v2i_4: " << v2i_4.getstring(s1) << endl;
28 Vector3f v3f_1;
29 Vector3f v3f_2(1);
30 Vector3f v3f_3(1, 2, 3);
31 Vector3f v3f_4(v3f_3);
33 cout << setw(40) << "v3f_1: " << v3f_1.getstring(s1) << endl;
34 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
35 cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl;
36 cout << setw(40) << "v3f_4: " << v3f_4.getstring(s1) << endl;
38 Vector4d v4d_1;
39 Vector4d v4d_2(1);
40 Vector4d v4d_3(1, 2, 3, 4);
41 Vector4d v4d_4(v4d_3);
43 cout << setw(40) << "v4d_1: " << v4d_1.getstring(s1) << endl;
44 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
45 cout << setw(40) << "v4d_3: " << v4d_3.getstring(s1) << endl;
46 cout << setw(40) << "v4d_4: " << v4d_4.getstring(s1) << endl;
47 }
49 {
50 cout << "===============================================================" << endl <<
51 "Testing Vector array indexing" << endl;
52 Vector2i v2i(1,2);
53 Vector3f v3f(1.1f, 2.2f, 3.3f);
54 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
56 cout << setw(40) << "v2i: " << v2i[0] << ", " << v2i[1] << endl;
57 cout << setw(40) << "v3f: " << v3f[0] << ", " << v3f[1] << ", " << v3f[2] << endl;
58 cout << setw(40) << "v4d: " << v4d[0] << ", " << v4d[1] << ", " << v4d[2] << ", " << v4d[3] << endl;
59 }
61 {
62 cout << "===============================================================" << endl <<
63 "Testing Vector assignment" << endl;
64 Vector2i v2i(1,2);
65 Vector3f v3f(1.1f, 2.2f, 3.3f);
66 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
67 Vector2i v2i_2;
68 Vector3f v3f_2;
69 Vector4d v4d_2;
71 cout << "Before assignment" << endl;
72 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
73 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
74 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
75 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
76 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
77 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
79 v2i_2 = v2i;
80 v3f_2 = v3f;
81 v4d_2 = v4d;
82 cout << "After assignment by =" << endl;
83 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
84 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
85 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
87 v2i_2.assign(1, 1);
88 v3f_2.assign(2.2, 2.2, 2.2);
89 v4d_2.assign(3.3, 3.3, 3.3, 3.3);
90 cout << "After assignment by assign()" << endl;
91 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
92 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
93 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
94 }
96 {
97 cout << "===============================================================" << endl <<
98 "Testing Vector comparison" << endl;
99 Vector2i v2i(1,2);
100 Vector3f v3f(1.1f, 2.2f, 3.3f);
101 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
102 Vector2i v2i_2;
103 Vector3f v3f_2;
104 Vector4d v4d_2;
106 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
107 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
108 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
109 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
110 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
111 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
112 cout << boolalpha;
113 cout << setw(40) << "v2i == v2i_2: " << (v2i == v2i_2) << endl;
114 cout << setw(40) << "v3f == v3f_2: " << (v3f == v3f_2) << endl;
115 cout << setw(40) << "v4d == v4d_2: " << (v4d == v4d_2) << endl;
116 cout << setw(40) << "v2i != v2i_2: " << (v2i != v2i_2) << endl;
117 cout << setw(40) << "v3f != v3f_2: " << (v3f != v3f_2) << endl;
118 cout << setw(40) << "v4d != v4d_2: " << (v4d != v4d_2) << endl;
119 }
121 {
122 cout << "===============================================================" << endl <<
123 "Testing Vector addition" << endl;
124 Vector2i v2i(1,2);
125 Vector3f v3f(1.1f, 2.2f, 3.3f);
126 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
127 Vector2i v2i_2(3,4);
128 Vector3f v3f_2(4.4, 5.5, 6.6);
129 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
130 Vector2i v2i_3;
131 Vector3f v3f_3 ;
132 Vector4d v4d_3;
134 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
135 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
136 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
137 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
138 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
139 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
140 v2i_3 = v2i + v2i_2;
141 v3f_3 = v3f + v3f_2;
142 v4d_3 = v4d + v4d_2;
143 cout << setw(40) << "v2i_3 = v2i + v2i_2: " << v2i_3.getstring(s1) << endl;
144 cout << setw(40) << "v3f_3 = v3f + v3f_2: " << v3f_3.getstring(s1) << endl;
145 cout << setw(40) << "v4d_3 = v4d + v4d_2: " << v4d_3.getstring(s1) << endl;
146 v2i_3 += v2i_2;
147 v3f_3 += v3f_2;
148 v4d_3 += v4d_3;
149 cout << setw(40) << "v2i_3 += v2i_2: " << v2i_3.getstring(s1) << endl;
150 cout << setw(40) << "v3f_3 += v3f_2: " << v3f_3.getstring(s1) << endl;
151 cout << setw(40) << "v4d_3 += v4d_3: " << v4d_3.getstring(s1) << endl;
152 }
154 {
155 cout << "===============================================================" << endl <<
156 "Testing Vector subtraction" << endl;
157 Vector2i v2i(1,2);
158 Vector3f v3f(1.1f, 2.2f, 3.3f);
159 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
160 Vector2i v2i_2(3,4);
161 Vector3f v3f_2(4.4, 5.5, 6.6);
162 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
163 Vector2i v2i_3;
164 Vector3f v3f_3;
165 Vector4d v4d_3;
167 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
168 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
169 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
170 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
171 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
172 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
173 v2i_3 = v2i - v2i_2;
174 v3f_3 = v3f - v3f_2;
175 v4d_3 = v4d - v4d_2;
176 cout << setw(40) << "v2i_3 = v2i - v2i_2: " << v2i_3.getstring(s1) << endl;
177 cout << setw(40) << "v3f_3 = v3f - v3f_2: " << v3f_3.getstring(s1) << endl;
178 cout << setw(40) << "v4d_3 = v4d - v4d_2: " << v4d_3.getstring(s1) << endl;
179 v2i_3 -= v2i_2;
180 v3f_3 -= v3f_2;
181 v4d_3 -= v4d_3;
182 cout << setw(40) << "v2i_3 -= v2i_2: " << v2i_3.getstring(s1) << endl;
183 cout << setw(40) << "v3f_3 -= v3f_2: " << v3f_3.getstring(s1) << endl;
184 cout << setw(40) << "v4d_3 -= v4d_3: " << v4d_3.getstring(s1) << endl;
185 }
187 {
188 cout << "===============================================================" << endl <<
189 "Testing Vector scalar multiplication" << endl;
190 Vector2i v2i(1,2);
191 Vector3f v3f(1.1f, 2.2f, 3.3f);
192 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
193 Vector2i v2i_2;
194 Vector3f v3f_2;
195 Vector4d v4d_2;
196 int i = 2;
197 float f = 2.f;
198 double d = 2.0;
200 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
201 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
202 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
203 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
204 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
205 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
206 v2i_2 = v2i * i;
207 v3f_2 = v3f * f;
208 v4d_2 = v4d * d;
209 cout << setw(40) << "v2i_2 = v2i * i: " << v2i_2.getstring(s1) << endl;
210 cout << setw(40) << "v3f_2 = v3f * f: " << v3f_2.getstring(s1) << endl;
211 cout << setw(40) << "v4d_2 = v4d * d: " << v4d_2.getstring(s1) << endl;
212 v2i_2 *= i;
213 v3f_2 *= f;
214 v4d_2 *= d;
215 cout << setw(40) << "v2i_2 *= i: " << v2i_2.getstring(s1) << endl;
216 cout << setw(40) << "v3f_2 *= f: " << v3f_2.getstring(s1) << endl;
217 cout << setw(40) << "v4d_2 *= d: " << v4d_2.getstring(s1) << endl;
218 }
220 {
221 cout << "===============================================================" << endl <<
222 "Testing Vector scalar division" << endl;
223 Vector2i v2i(1,2);
224 Vector3f v3f(1.1f, 2.2f, 3.3f);
225 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
226 Vector2i v2i_2;
227 Vector3f v3f_2;
228 Vector4d v4d_2;
229 int i = 2;
230 float f = 2.f;
231 double d = 2.0;
233 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
234 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
235 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
236 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
237 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
238 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
239 v2i_2 = v2i / i;
240 v3f_2 = v3f / f;
241 v4d_2 = v4d / d;
242 cout << setw(40) << "v2i_2 = v2i / i: " << v2i_2.getstring(s1) << endl;
243 cout << setw(40) << "v3f_2 = v3f / f: " << v3f_2.getstring(s1) << endl;
244 cout << setw(40) << "v4d_2 = v4d / d: " << v4d_2.getstring(s1) << endl;
245 v2i_2 /= i;
246 v3f_2 /= f;
247 v4d_2 /= d;
248 cout << setw(40) << "v2i_2 /= i: " << v2i_2.getstring(s1) << endl;
249 cout << setw(40) << "v3f_2 /= f: " << v3f_2.getstring(s1) << endl;
250 cout << setw(40) << "v4d_2 /= d: " << v4d_2.getstring(s1) << endl;
251 }
253 {
254 cout << "===============================================================" << endl <<
255 "Testing Vector cross product" << endl;
256 Vector3f v3f(1.1f, 2.2f, 3.3f);
257 Vector3f v3f_2(4.4, 5.5, 6.6);
258 Vector3f v3f_3;
259 Vector3f v3f_4;
260 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
261 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
262 cout << setw(40) << "v3f_3: " << v3f_3.getstring(s1) << endl;
263 v3f.cross(v3f_2, v3f_3);
264 cout << setw(40) << "v3f.cross(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl;
265 v3f_4 = 2.0 * v3f.cross(v3f_2);
266 cout << setw(40) << "2.0 * v3f.cross(v3f_2,): " << v3f_4.getstring(s1) << endl;
267 v3f_4.assign(0,0,0);
268 v3f.cross(v3f_2, v3f_4);
269 cout << setw(40) << "v3f.cross(v3f_2, v3f_4): " << v3f_4.getstring(s1) << endl;
270 }
272 {
273 cout << "===============================================================" << endl <<
274 "Testing Vector dot product" << endl;
275 Vector2i v2i(1, 2);
276 Vector2i v2i_2(3, 4);
277 Vector3f v3f(1.1f, 2.2f, 3.3f);
278 Vector3f v3f_2(4.4, 5.5, 6.6);
279 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
280 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
281 int i;
282 float f;
283 double d;
284 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
285 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
286 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
287 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
288 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
289 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
290 i = v2i.dot(v2i_2);
291 cout << setw(40) << "i = v2i.dot(v2i_2): " << i << endl;
292 f = v3f.dot(v3f_2);
293 cout << setw(40) << "f = v3f.dot(v3f_2): " << f << endl;
294 d = v4d.dot(v4d_2);
295 cout << setw(40) << "d = v4d.dot(v4d_2): " << d << endl;
296 }
298 {
299 cout << "===============================================================" << endl <<
300 "Testing Vector length" << endl;
301 Vector2i v2i(1, 2);
302 Vector3f v3f(1.1f, 2.2f, 3.3f);
303 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
304 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
305 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
306 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
307 cout << setw(40) << "v2i.length(): " << v2i.length() << endl;
308 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
309 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
310 }
312 {
313 cout << "===============================================================" << endl <<
314 "Testing Vector normalize" << endl;
315 Vector2f v2f(1.1, 2.2);
316 Vector3f v3f(1.1f, 2.2f, 3.3f);
317 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
318 cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl;
319 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
320 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
321 v2f.normalize();
322 cout << setw(40) << "v2f.normalize() " << v2f.getstring(s1) << endl;
323 v3f.normalize();
324 cout << setw(40) << "v3f.normalize() " << v3f.getstring(s1) << endl;
325 v4d.normalize();
326 cout << setw(40) << "v4d.normalize() " << v4d.getstring(s1) << endl;
327 cout << setw(40) << "v2f.length(): " << v2f.length() << endl;
328 cout << setw(40) << "v3f.length(): " << v3f.length() << endl;
329 cout << setw(40) << "v4d.length(): " << v4d.length() << endl;
330 }
332 {
333 cout << "===============================================================" << endl <<
334 "Testing Vector get_angle" << endl;
335 Vector2i v2i(1, 2);
336 Vector2i v2i_2(3, 4);
337 Vector3f v3f(1.1f, 2.2f, 3.3f);
338 Vector3f v3f_2(4.4, 5.5, 6.6);
339 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
340 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
341 double d;
342 cout << setw(40) << "v2i: " << v2i.getstring(s1) << endl;
343 cout << setw(40) << "v2i_2: " << v2i_2.getstring(s1) << endl;
344 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
345 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
346 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
347 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
348 d = v2i.get_angle(v2i_2);
349 cout << setw(40) << "d = v2i.get_angle(v2i_2): " << d << endl;
350 d = v3f.get_angle(v3f_2);
351 cout << setw(40) << "d = v3f.get_angle(v3f_2): " << d << endl;
352 d = v4d.get_angle(v4d_2);
353 cout << setw(40) << "d = v4d.get_angle(v4d_2): " << d << endl;
354 }
356 {
357 cout << "===============================================================" << endl <<
358 "Testing Vector get_anglen" << endl;
359 Vector2f v2f(1.1, 2.2);
360 Vector2f v2f_2(3.3, 4.4);
361 Vector3f v3f(1.1f, 2.2f, 3.3f);
362 Vector3f v3f_2(4.4, 5.5, 6.6);
363 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
364 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
365 double d;
366 v2f.normalize();
367 v2f_2.normalize();
368 v3f.normalize();
369 v3f_2.normalize();
370 v4d.normalize();
371 v4d_2.normalize();
372 cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl;
373 cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl;
374 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
375 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
376 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
377 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
378 d = v2f.get_anglen(v2f_2);
379 cout << setw(40) << "d = v2f.get_anglen(v2f_2): " << d << endl;
380 d = v3f.get_anglen(v3f_2);
381 cout << setw(40) << "d = v3f.get_anglen(v3f_2): " << d << endl;
382 d = v4d.get_anglen(v4d_2);
383 cout << setw(40) << "d = v4d.get_anglen(v4d_2): " << d << endl;
384 }
386 {
387 cout << "===============================================================" << endl <<
388 "Testing Vector get_proj" << endl;
389 Vector2f v2f(1.1, 2.2);
390 Vector2f v2f_2(3.3, 4.4);
391 Vector2f v2f_3;
392 Vector3f v3f(1.1f, 2.2f, 3.3f);
393 Vector3f v3f_2(4.4, 5.5, 6.6);
394 Vector3f v3f_3;
395 Vector4d v4d(1.1, 2.2, 3.3, 4.4);
396 Vector4d v4d_2(5.5, 6.6, 7.7, 8.8);
397 Vector4d v4d_3;
398 cout << setw(40) << "v2f: " << v2f.getstring(s1) << endl;
399 cout << setw(40) << "v2f_2: " << v2f_2.getstring(s1) << endl;
400 cout << setw(40) << "v3f: " << v3f.getstring(s1) << endl;
401 cout << setw(40) << "v3f_2: " << v3f_2.getstring(s1) << endl;
402 cout << setw(40) << "v4d: " << v4d.getstring(s1) << endl;
403 cout << setw(40) << "v4d_2: " << v4d_2.getstring(s1) << endl;
404 v2f_3 = v2f.proj(v2f_2);
405 cout << setw(40) << "v2f_3 = v2f.proj(v3f_2): " << v2f_3.getstring(s1) << endl;
406 v3f_3 = v3f.proj(v3f_2);
407 cout << setw(40) << "v3f_3 = v3f.proj(v3f_2): " << v3f_3.getstring(s1) << endl;
408 v4d_3 = v4d.proj(v4d_2);
409 cout << setw(40) << "v4d_3 = v4d.proj(v4d_2): " << v4d_3.getstring(s1) << endl;
410 v2f_3.assign(0,0);
411 v3f_3.assign(0,0,0);
412 v4d_3.assign(0,0,0,0);
413 v2f.proj(v2f_2, v2f_3);
414 cout << setw(40) << "v2f.proj(v2f_2, v2f_3): " << v2f_3.getstring(s1) << endl;
415 v3f.proj(v3f_2, v3f_3);
416 cout << setw(40) << "v3f.proj(v3f_2, v3f_3): " << v3f_3.getstring(s1) << endl;
417 v4d.proj(v4d_2, v4d_3);
418 cout << setw(40) << "v4d.proj(v4d_2, v4d_3): " << v4d_3.getstring(s1) << endl;
419 }
421 }
423 ////////////////////////////////////////////////////////////////////////////////
424 void test_matrix(void)
425 {
426 string s;
427 }
429 ////////////////////////////////////////////////////////////////////////////////
430 void test_all(void)
431 {
432 test_vector();
433 test_matrix();
434 }
436 ////////////////////////////////////////////////////////////////////////////////
437 void show_menu(void)
438 {
439 cout << endl << endl
440 << "Test what?" << endl
441 << "0) All" << endl << endl
442 << "1) Vector" << endl
443 << "2) Matrix" << endl
444 << endl
445 << "99 Quit" << endl;
446 }
448 ////////////////////////////////////////////////////////////////////////////////
449 int main (int argc, char * argv[])
450 {
451 int retval = 0;
453 try
454 {
455 int choice = -1;
457 while (choice != 99)
458 {
459 show_menu();
460 cin >> choice;
461 if(!cin)
462 {
463 cin.clear();
464 cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
465 }
466 if (choice != 99)
467 {
468 switch (choice)
469 {
470 case 0:
471 test_all();
472 break;
473 case 1:
474 test_vector();
475 break;
476 case 2:
477 test_matrix();
478 break;
479 default:
480 cout << "Unrecognized choice. Please try again." << endl;
481 }
482 choice = -1;
483 }
484 }
485 }
486 catch (const std::exception & error)
487 {
488 string e = "Caught exception: ";
489 e += error.what();
490 cerr << e << endl;
491 retval = 1;
492 }
494 return retval;;
496 }