13 vec1
.addComponent(0.0);
14 vec1
.addComponent(0.0);
15 vec1
.addComponent(0.0);
17 vec2
.addComponent(1.0);
18 vec2
.addComponent(2.0);
19 vec2
.addComponent(3.0);
20 vec2
.addComponent(4.0);
22 vec3
.addComponent(2.7);
23 vec3
.addComponent(5.6);
24 vec3
.addComponent(45.2);
26 vec4
.addComponent(0.58);
27 vec4
.addComponent(-23.5);
28 vec4
.addComponent(12.7);
30 cout
<< "Test 1 : showing vectors" << endl
;
31 cout
<< "vector 1, must be (0,0,0)" << endl
;
34 cout
<< "vector 2, must be (1,2,3,4)" << endl
;
37 cout
<< "vector 3, must be (2.7,5.6,45.2)" << endl
;
40 cout
<< "vector 4, must be (0.58, -23.5, 12.7)" << endl
;
43 cout
<< "Test 2 : equality" << endl
;
46 vec2b
.addComponent(1.0);
47 vec2b
.addComponent(2.0);
48 vec2b
.addComponent(3.0);
49 vec2b
.addComponent(4.0);
51 cout
<< "Must return true : " << boolalpha
<< vec2
.equals(vec2b
) << endl
;
52 cout
<< "Must return false : " << boolalpha
<< vec3
.equals(vec4
) << endl
<< endl
;
54 cout
<< "Test 3 : adding / substracting vectors" << endl
;
56 cout
<< "vector 1 + vector 3 = (2.7, 5.6, 45.2)" << endl
;
57 vec1
.add(vec3
).show();
59 cout
<< "vector 3 - vector 2 => std::logic_error" << endl
;
61 vec3
.substract(vec2
).show();
63 catch (std::logic_error e
) {
64 cout
<< e
.what() << endl
;
67 cout
<< "vector 4 + vector 3 = (3.28, -17.9, 57.9)" << endl
;
68 vec4
.add(vec3
).show();
70 cout
<< "Test 4 : external product" << endl
;
71 cout
<< "2 * vector 1 = (0,0,0)" << endl
;
72 vec1
.externalProduct(2).show();
74 cout
<< "1.5 * vector 2 = (1.5, 3.0, 4.5, 6.0)" << endl
;
75 vec2
.externalProduct(1.5).show();
77 cout
<< "Test 5 : dot product" << endl
;
78 cout
<< "vector 1 dot vector 2 => std::logic_error" << endl
;
80 vec1
.dotProduct(vec2
);
82 catch (std::logic_error e
) {
83 cout
<< e
.what() << endl
;
86 cout
<< "vector 1 dot vector 3 = 0" << endl
;
87 cout
<< vec1
.dotProduct(vec3
) << endl
;
89 cout
<< "vector 2 dot vector 2 = 30" << endl
;
90 cout
<< vec2
.dotProduct(vec2
) << endl
<< endl
;
92 cout
<< "Test 6 : cross product" << endl
;
93 cout
<< "vector 2 cross vector 2 => std::logic_error" << endl
;
95 vec2
.crossProduct(vec2
).show();
97 catch (std::logic_error e
) {
98 cout
<< e
.what() << endl
;
101 cout
<< "vector 3 cross vector 4 = (1133.32, -8.074, -6.6698)" << endl
;
102 vec3
.crossProduct(vec4
).show();
104 cout
<< "Test 7 : magnitudes" << endl
;
105 cout
<< "mag(vec1) = 0" << endl
;
106 cout
<< vec1
.magnitude() << endl
;
108 cout
<< "mag(vec2) = 5.47723" << endl
;
109 cout
<< vec2
.magnitude() << endl
;
110 cout
<< "mag2(vec2) = 30" << endl
;
111 cout
<< vec2
.magnitude2() << endl
;
114 cout
<< "Test 8 : dimensions" << endl
;
115 cout
<< "dim(vec2) = 4" << endl
;
116 cout
<< vec2
.dimension() << endl
;
118 cout
<< "dim(vec3) = 3" << endl
;
119 cout
<< vec3
.dimension() << endl
<< endl
;
121 cout
<< "End" << endl
;