]> git.xonotic.org Git - xonotic/gmqcc.git/blob - tests/ternary.qc
add .gitignore file
[xonotic/gmqcc.git] / tests / ternary.qc
1 void     print(...)   = #1;
2 string   ftos (float) = #2;
3
4 void test(float cond, float v1, float v2, float a) {
5     print(ftos(cond ? v1 : v2), " ");
6     print( (cond ? v1 : v2) ? ( (a == 1) ? "a=1"
7                               : (a == 2) ? "a=2"
8                               : "a=other"
9                               )
10                             : "not met",
11           "\n");
12 }
13
14 void select_a(float x) {
15     print("select_a: ", ftos(x), "\n");
16 }
17 void select_b(float x) {
18     print("select_b: ", ftos(x), "\n");
19 }
20
21 void main() {
22     float a, b;
23     test(0, -99, 1, 1);
24     test(0, -99, 1, 2);
25     test(0, -99, 1, 3);
26     test(0, -99, 0, 1);
27     test(0, -99, 0, 2);
28     test(0, -99, 0, 3);
29     test(1, 1, -99, 1);
30     test(1, 1, -99, 2);
31     test(1, 1, -99, 3);
32     test(1, 0, -99, 1);
33     test(1, 0, -99, 2);
34     test(1, 0, -99, 3);
35
36     b = 5;
37     a = b ? 5 : 6;
38     print(ftos(a), "\n");
39     b ? a = 9 : a = 10;
40     print(ftos(a), "\n");
41     !b ? a = 9 : a = 10;
42     print(ftos(a), "\n");
43
44     ((1) ? select_a : select_b) (1);
45     ((0) ? select_a : select_b) (0);
46 }