6 bool test (const Vector
&testVal
, const Vector
&refVal
) {return (testVal
== refVal
);}
7 bool test (const double testVal
, const double refVal
) {return (testVal
== refVal
);}
11 Vector
vec1 (vector
<double> (5,1));
12 Vector
vec2 (vector
<double> (5, -2.25));
15 Vector
e3 (8, Vector::ei
, 3);
18 cout
<< "**** Beginnning of preliminary testing ****" << endl
<< endl
;
20 cout
<< "Testing constructors. Output should be (1 1 1 1 1), \n(-2.25 -2.25 -2.25 -2.25 -2.25), 2x(0 0 0 0) and e3 in R8" << endl
;
27 cout
<< "Testing overload of operator << (implementation only for testing purpose)" << endl
<< "Output should be (0 0 0 0)" << endl
;
30 cout
<< "Testing operator = : Output should be (-2.25 -2.25 -2.25 -2.25-2.25)" << endl
;
35 cout
<< "Testing operator == : output should be FALSE TRUE" << endl
;
36 cout
<< boolalpha
<< (vec1
== vec2
) << '\t' << (vec3
== vec2
) << endl
<< endl
;
38 cout
<< "**** End of preliminary testing ****" << endl
39 << "/!\\ If any of the above tests failed, discard rest of tests /!\\" << endl
<< endl
;
41 cout
<< "**** Beginning of methods testing ****" << endl
<< endl
;
43 cout
<< "at() const test : ";
44 cout
<< boolalpha
<< ( test(vec2
.at(2), -2.25) and test(e3
.at(3), 0) ) << endl
;
46 cout
<< "at() non const test : "; {
47 Vector
e4 (4, Vector::ei
, 1);
50 cout
<< boolalpha
<< ( test(e4
.at(0), 1) and test(e4
.at(3), 3.1415) ) << endl
;
53 cout
<< "'addComponent()' test : "; {
57 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
61 cout
<< "magnitude() test : ";
62 Vector
vec5 (vector
<double>(25, 5));
63 cout
<< boolalpha
<< test(vec5
.magnitude(), 25) << endl
;
64 cout
<< "magnitude2() test : ";
65 cout
<< boolalpha
<< test (vec1
.magnitude2(), 5) << endl
;
67 cout
<< "show() test : Output should be (0 0 1 0 0 0 0 0)" << endl
;
70 cout
<< "**** End of methods testing ****" << endl
<< endl
;
72 cout
<< "**** Beginning of operators testing ****" << endl
<< endl
;
74 cout
<< "Operator + test : "; {
76 Vector
refVal (vector
<double> (5,-1.25));
77 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
80 cout
<< "Operator += test : "; {
82 Vector
refVal (vector
<double> (5,-0.25));
83 cout
<< boolalpha
<< test (vec1
, refVal
) << endl
;
86 cout
<< "Operator - test : "; {
88 Vector
refVal (vector
<double> (5,2));
89 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
92 cout
<< "Operator -= test : "; {
94 Vector
refVal (vector
<double> (5,-4.25));
95 cout
<< boolalpha
<< test (vec2
, refVal
) << endl
;
98 cout
<< "Operator * (scalar) test : "; {
100 Vector
refVal (vector
<double> (5,0.75));
101 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
104 cout
<< "Operator *= (scalar) test : "; {
106 Vector
refVal (vector
<double> (5,-1));
107 cout
<< boolalpha
<< test (vec1
, refVal
) << endl
;
110 cout
<< "Operator * (dotProduct) test : "; {
111 cout
<< boolalpha
<< test ((vec2
* vec3
), -15.9375) << endl
;
114 cout
<< "Operator / test : "; {
115 Vector
a (vector
<double> (5, -6));
117 Vector
refVal (vector
<double> (5,2));
118 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
121 cout
<< "Operator /= test : "; {
122 Vector
a (vector
<double> (5, 1.75));
124 Vector
refVal (vector
<double> (5,1.4));
125 cout
<< boolalpha
<< test (a
, refVal
) << endl
;
128 cout
<< "Operator ^ test : "; {
129 Vector
e2 (3, Vector::ei
, 2);
133 a
.addComponent(2.27);
135 refVal
.addComponent(2.27);
136 refVal
.addComponent(0);
137 refVal
.addComponent(-5.0);
138 cout
<< boolalpha
<< test ((e2
^a
), refVal
) << endl
;
141 cout
<< "Operator != test : ";
142 cout
<< boolalpha
<< ((vec1
!= vec2
) == true) << endl
;
144 cout
<< "Operator [] test : "; {
145 cout
<< boolalpha
<< ( test(vec1
[5], -1) and test(vec3
[2], 2) ) << endl
;
149 cout
<< "**** End of testing operators ****" << endl
<< endl
;
151 cout
<< "**** Beginning of exception handling testing ****" << endl
<< endl
;
154 cout
<< "Operator +" << endl
;
157 catch (logic_error
&e
) {
158 cout
<< e
.what() << endl
;
162 cout
<< "Operator +=" << endl
;
165 catch (logic_error
&e
) {
166 cout
<< e
.what() << endl
;
170 cout
<< "Operator -" << endl
;
173 catch (logic_error
&e
) {
174 cout
<< e
.what() << endl
;
178 cout
<< "Operator -=" << endl
;
181 catch (logic_error
&e
) {
182 cout
<< e
.what() << endl
;
186 cout
<< "Operator *" << endl
;
189 catch (logic_error
&e
) {
190 cout
<< e
.what() << endl
;
194 cout
<< "Operator /" << endl
;
197 catch (domain_error
&e
) {
198 cout
<< e
.what() << endl
;
202 cout
<< "Operator /=" << endl
;
205 catch (domain_error
&e
) {
206 cout
<< e
.what() << endl
;
210 cout
<< "Operator ^" << endl
;
213 catch (logic_error
&e
) {
214 cout
<< e
.what() << endl
;
218 cout
<< "at() const" << endl
;
221 catch (out_of_range
&e
) {
222 cout
<< e
.what() << endl
;
226 cout
<< "at() non-const" << endl
;
229 catch (out_of_range
&e
) {
230 cout
<< e
.what() << endl
;
234 cout
<< "[] const" << endl
;
237 catch (out_of_range
&e
) {
238 cout
<< e
.what() << endl
;
242 cout
<< "[] non-const" << endl
;
245 catch (out_of_range
&e
) {
246 cout
<< e
.what() << endl
;
249 cout
<< endl
<< endl
<< "**** End of testing ****" << endl
<< endl
;