6 bool test (const Vector
&testVal
, const Vector
&refVal
) {return (testVal
== refVal
);}
7 bool test (const double testVal
, const double refVal
) {return (testVal
== refVal
);}
9 ostream
& operator << (ostream
& os
, const Vector
&aVector
)
11 const unsigned int SIZE (aVector
.dimension());
13 for (unsigned int i(0) ; i
< SIZE
; ++i
) {
14 os
<< aVector
.at(i
) << ' ';
21 Vector
vec1 (vector
<double> (5,1));
22 Vector
vec2 (vector
<double> (5, -2.25));
25 Vector
e3 (8, Vector::ei
, 3);
28 cout
<< "**** Beginnning of preliminary testing ****" << endl
<< endl
;
30 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
;
37 cout
<< "Testing overload of operator << (implementation only for testing purpose)" << endl
<< "Output should be (0 0 0 0)" << endl
;
40 cout
<< "Testing operator = : Output should be (-2.25 -2.25 -2.25 -2.25-2.25)" << endl
;
45 cout
<< "Testing operator == : output should be FALSE TRUE" << endl
;
46 cout
<< boolalpha
<< (vec1
== vec2
) << '\t' << (vec3
== vec2
) << endl
<< endl
;
48 cout
<< "**** End of preliminary testing ****" << endl
49 << "/!\\ If any of the above tests failed, discard rest of tests /!\\" << endl
<< endl
;
51 cout
<< "**** Beginning of methods testing ****" << endl
<< endl
;
53 cout
<< "at() const test : ";
54 cout
<< boolalpha
<< ( test(vec2
.at(2), -2.25) and test(e3
.at(3), 0) ) << endl
;
56 cout
<< "at() non const test : "; {
57 Vector
e4 (4, Vector::ei
, 1);
60 cout
<< boolalpha
<< ( test(e4
.at(0), 1) and test(e4
.at(3), 3.1415) ) << endl
;
63 cout
<< "'addComponent()' test : "; {
67 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
71 cout
<< "magnitude() test : ";
72 Vector
vec5 (vector
<double>(25, 5));
73 cout
<< boolalpha
<< test(vec5
.magnitude(), 25) << endl
;
74 cout
<< "magnitude2() test : ";
75 cout
<< boolalpha
<< test (vec1
.magnitude2(), 5) << endl
;
77 cout
<< "show() test : Output should be (0 0 1 0 0 0 0 0)" << endl
;
80 cout
<< "**** End of methods testing ****" << endl
<< endl
;
82 cout
<< "**** Beginning of operators testing ****" << endl
<< endl
;
84 cout
<< "Operator + test : "; {
86 Vector
refVal (vector
<double> (5,-1.25));
87 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
90 cout
<< "Operator += test : "; {
92 Vector
refVal (vector
<double> (5,-0.25));
93 cout
<< boolalpha
<< test (vec1
, refVal
) << endl
;
96 cout
<< "Operator - test : "; {
98 Vector
refVal (vector
<double> (5,2));
99 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
102 cout
<< "Operator -= test : "; {
104 Vector
refVal (vector
<double> (5,-4.25));
105 cout
<< boolalpha
<< test (vec2
, refVal
) << endl
;
108 cout
<< "Operator * (scalar) test : "; {
110 Vector
refVal (vector
<double> (5,0.75));
111 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
114 cout
<< "Operator *= (scalar) test : "; {
116 Vector
refVal (vector
<double> (5,-1));
117 cout
<< boolalpha
<< test (vec1
, refVal
) << endl
;
120 cout
<< "Operator * (dotProduct) test : "; {
121 cout
<< boolalpha
<< test ((vec2
* vec3
), -15.9375) << endl
;
124 cout
<< "Operator / test : "; {
125 Vector
a (vector
<double> (5, -6));
127 Vector
refVal (vector
<double> (5,2));
128 cout
<< boolalpha
<< test (vec3
, refVal
) << endl
;
131 cout
<< "Operator /= test : "; {
132 Vector
a (vector
<double> (5, 1.75));
134 Vector
refVal (vector
<double> (5,1.4));
135 cout
<< boolalpha
<< test (a
, refVal
) << endl
;
138 cout
<< "Operator ^ test : "; {
139 Vector
e2 (3, Vector::ei
, 2);
143 a
.addComponent(2.27);
145 refVal
.addComponent(2.27);
146 refVal
.addComponent(0);
147 refVal
.addComponent(-5.0);
148 cout
<< boolalpha
<< test ((e2
^a
), refVal
) << endl
;
151 cout
<< "Operator != test : ";
152 cout
<< boolalpha
<< ((vec1
!= vec2
) == true) << endl
;
154 cout
<< "Operator [] test : "; {
155 cout
<< boolalpha
<< ( test(vec1
[5], -1) and test(vec3
[2], 2) ) << endl
;
159 cout
<< "**** End of testing operators ****" << endl
<< endl
;
161 cout
<< "**** Beginning of exception handling testing ****" << endl
<< endl
;
164 cout
<< "Operator +" << endl
;
167 catch (logic_error
&e
) {
168 cout
<< e
.what() << endl
;
172 cout
<< "Operator +=" << endl
;
175 catch (logic_error
&e
) {
176 cout
<< e
.what() << endl
;
180 cout
<< "Operator -" << endl
;
183 catch (logic_error
&e
) {
184 cout
<< e
.what() << endl
;
188 cout
<< "Operator -=" << endl
;
191 catch (logic_error
&e
) {
192 cout
<< e
.what() << endl
;
196 cout
<< "Operator *" << endl
;
199 catch (logic_error
&e
) {
200 cout
<< e
.what() << endl
;
204 cout
<< "Operator /" << endl
;
207 catch (domain_error
&e
) {
208 cout
<< e
.what() << endl
;
212 cout
<< "Operator /=" << endl
;
215 catch (domain_error
&e
) {
216 cout
<< e
.what() << endl
;
220 cout
<< "Operator ^" << endl
;
223 catch (logic_error
&e
) {
224 cout
<< e
.what() << endl
;
228 cout
<< "at() const" << endl
;
231 catch (out_of_range
&e
) {
232 cout
<< e
.what() << endl
;
236 cout
<< "at() non-const" << endl
;
239 catch (out_of_range
&e
) {
240 cout
<< e
.what() << endl
;
244 cout
<< "[] const" << endl
;
247 catch (out_of_range
&e
) {
248 cout
<< e
.what() << endl
;
252 cout
<< "[] non-const" << endl
;
255 catch (out_of_range
&e
) {
256 cout
<< e
.what() << endl
;
259 cout
<< endl
<< endl
<< "**** End of testing ****" << endl
<< endl
;