Merge branch 'vector-Rn'
[ProjetInfo.git] / testvector3.cc
blob6bc42a6ad5fcacecf5d4701b40c49ca0238c4fbc
1 #include <iostream>
2 #include "vector3.h"
4 using namespace std;
6 int main ()
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;
11 vec1.show();
12 vec2.show();
13 e1.show();
15 cout << "Copy constructor test :" << endl << "Output should be (2 2 2)" << endl;
16 Vector3 vec3 (vec2);
17 vec3.show();
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;
32 e1 += vec2;
33 e1.show();
34 cout << "Operator -= test : e1 -= vec2 = (1 0 0)" << endl;
35 e1 -= vec2;
36 e1.show();
38 cout << "Operator + test : vec1 = e1 + vec2 = (3 2 2)" << endl;
39 vec1 = e1 + vec2;
40 vec1.show();
42 cout << "Operator - test : vec1 = e1 - vec2 = (-1 -2 -2)" << endl;
43 vec1 = e1 - vec2;
44 vec1.show();
46 cout << "Operator *= 'scalar' test : vec1 *= -1.5 = (1.5 3 3)" << endl;
47 vec1 *= -1.5;
48 vec1.show();
50 cout << "Operator * 'scalar' test : vec3 = vec1*2.5 = (3.75 7.5 7.5)" << endl;
51 vec3 = vec1*2.5;
52 vec3.show();
54 cout << "Operator /= test : vec3 /= 5 = (0.75 1.5 1.5)" << endl;
55 vec3 /= 5;
56 vec3.show();
58 cout << "Operator /= : attempting division by zero..." << endl;
59 try {
60 vec3 /= 0.0;
62 catch (domain_error& e) {
63 cout << e.what() << endl << endl;
66 cout << "Operator / test : vec2 = vec1 / 0.75 = (2 4 4)" << endl;
67 vec2 = vec1 / 0.75;
68 vec2.show();
70 cout << "Operator / : attempting division by zero..." << endl;
71 try {
72 vec2 = vec1 / 0.0;
74 catch (domain_error& e) {
75 cout << e.what() << endl << endl;
78 cout << "Operator ^ test : vec1 = e1 x vec2 = (0 -4 4)" << endl;
79 vec1 = e1 ^ vec2;
80 vec1.show();
82 cout << "Operator ^ test : vec1 = vec2 x e1 = (0 4 -4)" << endl;
83 vec1 = vec2 ^ e1;
84 vec1.show();
86 cout << "Operator = test : vec1 = vec4 = (1 3 7)" << endl;
87 Vector3 vec4 (1, 3, 7);
88 vec1 = vec4;
89 vec1.show();
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;
98 vec1.show();
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;
101 vec1[1] = 3;
102 vec1[3] = 3.1415;
103 vec1.show();
105 cout << "Operator [] : attempting vec1[4]" << endl;
106 try {
107 cout << vec1[4] << endl;
109 catch (out_of_range& e) {
110 cout << e.what() << endl << endl;
113 cout << "Operator [] : attempting vec1[0]" << endl;
114 try {
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;
123 return 0;