8 Vector3 vec1
, vec2 (2.0, 2.0, 2.0), e1 (Vector3::e1
);
10 cout
<< "Initialisation test :" << endl
<< "Output should be (0 0 0), (2 2 2), (1 0 0)" << endl
;
15 cout
<< "Copy constructor test :" << endl
<< "Output should be (2 2 2)" << endl
;
20 cout
<< endl
<< "**** Beginning of methods testing ****" << endl
;
22 cout
<< "Magnitude test :" << endl
<< "Output should be 3.4641 and 12" << endl
;
23 cout
<< vec2
.magnitude() << '\t' << vec2
.magnitude2() << endl
;
25 cout
<< "Dot product test :" << endl
<< "vec2 * e1 = 2 and vec2 * vec3 = 12" << endl
;
26 cout
<< vec2
.dotProduct(e1
) << '\t' << vec2
.dotProduct(vec3
) << endl
;
29 cout
<< endl
<< "**** Beginning of operators testing ****" << endl
;
31 cout
<< "Operator += test : e1 += vec2 = (3 2 2)" << endl
;
34 cout
<< "Operator -= test : e1 -= vec2 = (1 0 0)" << endl
;
38 cout
<< "Operator + test : vec1 = e1 + vec2 = (3 2 2)" << endl
;
42 cout
<< "Operator - test : vec1 = e1 - vec2 = (-1 -2 -2)" << endl
;
46 cout
<< "Operator *= 'scalar' test : vec1 *= -1.5 = (1.5 3 3)" << endl
;
50 cout
<< "Operator * 'scalar' test : vec3 = vec1*2.5 = (3.75 7.5 7.5)" << endl
;
54 cout
<< "Operator /= test : vec3 /= 5 = (0.75 1.5 1.5)" << endl
;
58 cout
<< "Operator /= : attempting division by zero..." << endl
;
62 catch (domain_error
& e
) {
63 cout
<< e
.what() << endl
<< endl
;
66 cout
<< "Operator / test : vec2 = vec1 / 0.75 = (2 4 4)" << endl
;
70 cout
<< "Operator / : attempting division by zero..." << endl
;
74 catch (domain_error
& e
) {
75 cout
<< e
.what() << endl
<< endl
;
78 cout
<< "Operator ^ test : vec1 = e1 x vec2 = (0 -4 4)" << endl
;
82 cout
<< "Operator ^ test : vec1 = vec2 x e1 = (0 4 -4)" << endl
;
86 cout
<< "Operator = test : vec1 = vec4 = (1 3 7)" << endl
;
87 Vector3
vec4 (1, 3, 7);
91 cout
<< "Operator == test : vec1 == vec4 -> TRUE and vec1 == vec2 -> FALSE" << endl
;
92 cout
<< boolalpha
<< (vec1
== vec4
) << '\t' << (vec1
== vec2
) << endl
;
94 cout
<< "Operator != test : vec1 != vec3 -> TRUE and vec1 != vec4 -> FALSE" << endl
;
95 cout
<< boolalpha
<< (vec1
!= vec3
) << '\t' << (vec1
!= vec4
) << endl
<< endl
;
97 cout
<< "Operator [] test :" << endl
;
99 cout
<< "vec1[2] : " << vec1
[2] << "\t Should be 3" << endl
;
100 cout
<< "vec1[1] = 3 and vec1[3] = 3.1415. Output should be (3 3 3.1415)" << endl
;
105 cout
<< "Operator [] : attempting vec1[4]" << endl
;
107 cout
<< vec1
[4] << endl
;
109 catch (out_of_range
& e
) {
110 cout
<< e
.what() << endl
<< endl
;
113 cout
<< "Operator [] : attempting vec1[0]" << endl
;
115 cout
<< vec1
[0] << endl
;
117 catch (out_of_range
& e
) {
118 cout
<< e
.what() << endl
<< endl
;
121 cout
<< endl
<< endl
<< "**** End of testing ! ****" << endl
<< endl
;