2 #include "../../math/inc/vector3.h"
8 double array
[3] = {1, -2.36, 5.78};
9 Vector3 vec1
, vec2 (2.0, 2.0, 2.0), e1 (Vector3::e1
), vec (array
);
11 cout
<< "Initialisation test :" << endl
<< "Output should be (0 0 0), (2 2 2), (1 0 0) and (1 -2.36 5.78)" << endl
;
18 cout
<< "Copy constructor test :" << endl
<< "Output should be (2 2 2)" << endl
;
23 cout
<< endl
<< "**** Beginning of methods testing ****" << endl
<< endl
;
26 cout
<< "'setVector' test :" << endl
;
27 cout
<< "vec5.setVector(1), vec5.setVector(1.5 2.36), vec5.setVector(3.1415 -62.36 5)" << endl
;
28 cout
<< "Output should be (1 0 0), (1.5 2.36 0) and (3.1415 -62.36 5)" << endl
;
29 vec5
.setVector(1); vec5
.show();
30 vec5
.setVector(1.5, 2.36); vec5
.show();
31 vec5
.setVector(3.1415, -62.36, 5); vec5
.show();
34 cout
<< "Magnitude test :" << endl
<< "Output should be 3.4641 and 12" << endl
;
35 cout
<< vec2
.magnitude() << '\t' << vec2
.magnitude2() << endl
;
37 cout
<< "Dot product test :" << endl
<< "vec2 * e1 = 2 and vec2 * vec3 = 12" << endl
;
38 cout
<< vec2
.dotProduct(e1
) << '\t' << vec2
.dotProduct(vec3
) << endl
;
40 cout
<< endl
<< "**** End of methods testing ****" << endl
<< endl
;
43 cout
<< endl
<< "**** Beginning of operators testing ****" << endl
<<endl
;
45 cout
<< "Operator 'ostream& operator<< ()' test : Output should be (1 2.5 -3.74)" << endl
;
46 cout
<< vec
<< endl
<< endl
;
50 cout
<< endl
<< "**** Beginning of operators testing ****" << endl
<<endl
;
52 cout
<< "Operator 'ostream operator<< ()' test : Output should be (3.1415 -62.36 5)" << endl
;
53 cout
<< vec5
<< endl
<< endl
;
56 cout
<< "Operator += test : e1 += vec2 = (3 2 2)" << endl
;
59 cout
<< "Operator -= test : e1 -= vec2 = (1 0 0)" << endl
;
63 cout
<< "Operator + test : vec1 = e1 + vec2 = (3 2 2)" << endl
;
67 cout
<< "Operator - test : vec1 = e1 - vec2 = (-1 -2 -2)" << endl
;
71 cout
<< "Operator *= 'scalar' test : vec1 *= -1.5 = (1.5 3 3)" << endl
;
75 cout
<< "Operator * 'scalar' test : vec3 = vec1*2.5 = (3.75 7.5 7.5)" << endl
;
79 cout
<< "Operator /= test : vec3 /= 5 = (0.75 1.5 1.5)" << endl
;
83 cout
<< "Operator /= : attempting division by zero..." << endl
;
87 catch (domain_error
& e
) {
88 cout
<< e
.what() << endl
<< endl
;
91 cout
<< "Operator / test : vec2 = vec1 / 0.75 = (2 4 4)" << endl
;
95 cout
<< "Operator / : attempting division by zero..." << endl
;
99 catch (domain_error
& e
) {
100 cout
<< e
.what() << endl
<< endl
;
103 cout
<< "Operator ^ test : vec1 = e1 x vec2 = (0 -4 4)" << endl
;
107 cout
<< "Operator ^ test : vec1 = vec2 x e1 = (0 4 -4)" << endl
;
111 cout
<< "Operator = test : vec1 = vec4 = (1 3 7)" << endl
;
112 Vector3
vec4 (1, 3, 7);
116 cout
<< "Operator == test : vec1 == vec4 -> TRUE and vec1 == vec2 -> FALSE" << endl
;
117 cout
<< boolalpha
<< (vec1
== vec4
) << '\t' << (vec1
== vec2
) << endl
;
119 cout
<< "Operator != test : vec1 != vec3 -> TRUE and vec1 != vec4 -> FALSE" << endl
;
120 cout
<< boolalpha
<< (vec1
!= vec3
) << '\t' << (vec1
!= vec4
) << endl
<< endl
;
122 cout
<< "Operator [] test :" << endl
;
123 cout
<< "vec1[2] : " << vec1
[2] << "\t Should be 3" << endl
;
124 cout
<< "vec1[1] = 3 and vec1[3] = 3.1415. Output should be (3 3 3.1415)" << endl
;
129 cout
<< "Operator [] : attempting vec1[4]" << endl
;
131 cout
<< vec1
[4] << endl
;
133 catch (out_of_range
& e
) {
134 cout
<< e
.what() << endl
<< endl
;
137 cout
<< "Operator [] : attempting vec1[0]" << endl
;
139 cout
<< vec1
[0] << endl
;
141 catch (out_of_range
& e
) {
142 cout
<< e
.what() << endl
<< endl
;
145 cout
<< endl
<< endl
<< "**** End of testing ! ****" << endl
<< endl
;