Merge branch 'mat-devel'
[ProjetInfo.git] / testing / math / testVector3.cc
blobf412783a68a6d0b7e96251f42ba53597ef5d8a84
1 #include <iostream>
2 #include "../../math/inc/vector3.h"
4 using namespace std;
6 int main ()
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;
13 vec1.show();
14 vec2.show();
15 e1.show();
16 vec.show();
18 cout << "Copy constructor test :" << endl << "Output should be (2 2 2)" << endl;
19 Vector3 vec3 (vec2);
20 vec3.show();
23 cout << endl << "**** Beginning of methods testing ****" << endl << endl;
25 Vector3 vec5;
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;
41 <<<<<<< HEAD
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;
47 =======
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;
54 >>>>>>> vector-Rn
56 cout << "Operator += test : e1 += vec2 = (3 2 2)" << endl;
57 e1 += vec2;
58 e1.show();
59 cout << "Operator -= test : e1 -= vec2 = (1 0 0)" << endl;
60 e1 -= vec2;
61 e1.show();
63 cout << "Operator + test : vec1 = e1 + vec2 = (3 2 2)" << endl;
64 vec1 = e1 + vec2;
65 vec1.show();
67 cout << "Operator - test : vec1 = e1 - vec2 = (-1 -2 -2)" << endl;
68 vec1 = e1 - vec2;
69 vec1.show();
71 cout << "Operator *= 'scalar' test : vec1 *= -1.5 = (1.5 3 3)" << endl;
72 vec1 *= -1.5;
73 vec1.show();
75 cout << "Operator * 'scalar' test : vec3 = vec1*2.5 = (3.75 7.5 7.5)" << endl;
76 vec3 = vec1*2.5;
77 vec3.show();
79 cout << "Operator /= test : vec3 /= 5 = (0.75 1.5 1.5)" << endl;
80 vec3 /= 5;
81 vec3.show();
83 cout << "Operator /= : attempting division by zero..." << endl;
84 try {
85 vec3 /= 0.0;
87 catch (domain_error& e) {
88 cout << e.what() << endl << endl;
91 cout << "Operator / test : vec2 = vec1 / 0.75 = (2 4 4)" << endl;
92 vec2 = vec1 / 0.75;
93 vec2.show();
95 cout << "Operator / : attempting division by zero..." << endl;
96 try {
97 vec2 = vec1 / 0.0;
99 catch (domain_error& e) {
100 cout << e.what() << endl << endl;
103 cout << "Operator ^ test : vec1 = e1 x vec2 = (0 -4 4)" << endl;
104 vec1 = e1 ^ vec2;
105 vec1.show();
107 cout << "Operator ^ test : vec1 = vec2 x e1 = (0 4 -4)" << endl;
108 vec1 = vec2 ^ e1;
109 vec1.show();
111 cout << "Operator = test : vec1 = vec4 = (1 3 7)" << endl;
112 Vector3 vec4 (1, 3, 7);
113 vec1 = vec4;
114 vec1.show();
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;
125 vec1[1] = 3;
126 vec1[3] = 3.1415;
127 vec1.show();
129 cout << "Operator [] : attempting vec1[4]" << endl;
130 try {
131 cout << vec1[4] << endl;
133 catch (out_of_range& e) {
134 cout << e.what() << endl << endl;
137 cout << "Operator [] : attempting vec1[0]" << endl;
138 try {
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;
147 return 0;