source: tests/vector/vec2.cfa @ 1188195

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 1188195 was 0856a96, checked in by Dmitry Kobets <dkobets@…>, 5 years ago

Add unit tests for vec2

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "../../libcfa/src/vector.hfa"
2#include <fstream.hfa>
3
4int main(void) {
5    vec2 v1 = {1.,2.};
6    sout | "ctor(x,y):" | v1;
7
8    vec2 v2 = v1;
9    sout | "copy ctor:" | v2;
10
11    v2 = (vec2){3., 4.2};
12    sout | "assignment:" | v2;
13
14    v2 = v1;
15    sout | "move assignment:" | v2;
16
17    vec2 v3 = 0;
18    sout | "zero-init:" | v3;
19
20    v1 = 0;
21    sout | "zero-assign:" | v1;
22
23    vec2 v4 = {1.23};
24    sout | "fill-ctor:" | v4;
25
26    v1 = (vec2){1.23, 3.43};
27    sout | "?-?:" | (v1 - (vec2){1.21,3});
28
29    v1 -= (vec2){-2, 10};
30    sout | "?-=?:" | v1;
31
32    v1 = -v1;
33    sout | "-?:" | v1;
34
35    v1 = (vec2){1.5, 2.75};
36    sout | "?+?:" | (v1 + (vec2){0.8, -0.3});
37
38    v1 += (vec2){0.8, -0.3};
39    sout | "?+=?:" | v1;
40
41    v1 = (vec2){1.5, 2.75};
42    sout | "v*s:" | v1 * 3;
43
44    sout | "s*v:" | 3 * v1;
45
46    v1 *= 3;
47    sout | "?*=?:" | v1;
48
49    v1 = (vec2){2, -0.1};
50    sout | "?/?:" | (v1 / 3);
51
52    v1 /= 3;
53    sout | "?/=?:" | v1;
54
55    v1 = (vec2){2, 3};
56    v2 = (vec2){-3, 2};
57    sout | "dot_1:" | dot(v1, v2);
58
59    v2 = (vec2){1.3, 2};
60    sout | "dot_2:" | dot(v1, v2);
61
62    v1 = (vec2){4, 3};
63    sout | "length:" | length(v1);
64
65    sout | "length_squared:" | length_squared(v1);
66
67    v2 = (vec2){6, -3.2};
68    sout | "distance:" | distance(v1, v2);
69
70    sout | "normalize:" | normalize(v2);
71
72    v1 = (vec2){1,0};
73    sout | "normalize_2:" | normalize(v1);
74
75    sout | "project:" | project((vec2){5,6}, (vec2){1, 0});
76    sout | "project_2:" | project((vec2){5,6}, (vec2){1, 1});
77
78    v1 = (vec2){5,6};
79    v2 = (vec2){1,0};
80    sout | "reflect:" | reflect(v1,v2);
81
82    v2 = (vec2){0,-1};
83    sout | "refract:" | refract(v1,v2,1);
84    sout | "refract:" | refract(v1,v2,1./1.33);
85
86    vec2 geometric_normal = {5,6};
87    vec2 perturbed_normal = {4,5.5};
88    vec2 eyeline = {-1,0.002f};
89    sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal);
90
91    eyeline = (vec2){1,0.002f};
92    sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal);
93}
Note: See TracBrowser for help on using the repository browser.