]> git.xonotic.org Git - xonotic/gmqcc.git/blob - tests/correct-logic.qc
Test cases for -fcorrect-logic
[xonotic/gmqcc.git] / tests / correct-logic.qc
1 void   print(...)   = #1;
2 string ftos (float) = #2;
3
4 float test_s_not  (vector s)           { return !s; }
5 float test_s_and  (vector s, vector t) { return s && t; }
6 float test_s_or   (vector s, vector t) { return s || t; }
7 float test_s_if   (vector s)           { if (s) return 1; return 0; }
8 float test_s_ifnot(vector s)           { if not (s) return 1; return 0; }
9
10 void test(vector s, vector t) {
11     print(ftos(!!test_s_not  (s)), " ");
12     print(ftos(!!test_s_and  (s, t)), " ");
13     print(ftos(!!test_s_or   (s, t)), " ");
14     print(ftos(!!test_s_if   (s)), " ");
15     print(ftos(!!test_s_ifnot(s)), "\n");
16 }
17
18 void main() {
19     print("        ! & | i N\n");
20     print("0, 0 -> "); test('0 0 0', '0 0 0');
21     print("0, x -> "); test('0 0 0', '1 0 0');
22     print("x, 0 -> "); test('1 0 0', '0 0 0');
23     print("x, x -> "); test('1 0 0', '1 0 0');
24     print("0, y -> "); test('0 0 0', '0 1 0');
25     print("y, 0 -> "); test('0 1 0', '0 0 0');
26     print("y, y -> "); test('0 1 0', '0 1 0');
27 }