]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
A test for that xor stuff (the same one I used to cause the bug to manifest in the...
authorDale Weiler <killfieldengine@gmail.com>
Tue, 27 Aug 2013 10:35:58 +0000 (06:35 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 27 Aug 2013 10:35:58 +0000 (06:35 -0400)
tests/xor.qc
tests/xor.tmpl

index 531a5fb42be3427daa939816274a14658e12089b..df6900d2299efdc30d7250f621bce7c14f6d07fc 100644 (file)
@@ -3,38 +3,42 @@ vector swap(float x, float y) {
     // everyone knows this trick
     ret.x = x;
     ret.y = y;
     // everyone knows this trick
     ret.x = x;
     ret.y = y;
-    
+
     ret.x = ret.x ^ ret.y;
     ret.y = ret.y ^ ret.x;
     ret.x = ret.x ^ ret.y;
     ret.x = ret.x ^ ret.y;
     ret.y = ret.y ^ ret.x;
     ret.x = ret.x ^ ret.y;
-    
+
     return ret;
 }
 
     return ret;
 }
 
+float f(vector b) {
+    return b.x+b.y+b.z;
+}
+
 void main() {
     float x = 5;
     float y = 3;
     float z = x ^ y; // 6
 void main() {
     float x = 5;
     float y = 3;
     float z = x ^ y; // 6
-    
+
     float a = 2;
     float b = 10;
     float c = a ^ b; // 8
     float a = 2;
     float b = 10;
     float c = a ^ b; // 8
-    
+
     print(ftos(z), "\n");
     print(ftos(c), "\n");
     print(ftos(z), "\n");
     print(ftos(c), "\n");
-    
+
     // commutative?
     if (x ^ y == y ^ x)
         print("commutative\n");
     // commutative?
     if (x ^ y == y ^ x)
         print("commutative\n");
-    
+
     // assocative?
     if (x ^ (y ^ z) == (x ^ y) ^ z)
         print("assocative\n");
     // assocative?
     if (x ^ (y ^ z) == (x ^ y) ^ z)
         print("assocative\n");
-        
+
     // elements are their own inverse?
     if (x ^ 0 == x)
         print("inverse\n");
     // elements are their own inverse?
     if (x ^ 0 == x)
         print("inverse\n");
-        
+
     // vector ^ vector
     // vector ^ float
     // are legal in constant expressions (currently)
     // vector ^ vector
     // vector ^ float
     // are legal in constant expressions (currently)
@@ -43,13 +47,13 @@ void main() {
 
     print("vv: ", vtos(v1 ^ v2), "\n");
     print("vf: ", vtos(v1 ^ 10), "\n");
 
     print("vv: ", vtos(v1 ^ v2), "\n");
     print("vf: ", vtos(v1 ^ 10), "\n");
-    
+
     const vector v3 = '5 2 5' ^ '3 10 3';
     const vector v4 = '5 2 5' ^ 10;
     const vector v3 = '5 2 5' ^ '3 10 3';
     const vector v4 = '5 2 5' ^ 10;
-    
+
     print("vv: ", vtos(v3), "\n");
     print("vf: ", vtos(v4), "\n");
     print("vv: ", vtos(v3), "\n");
     print("vf: ", vtos(v4), "\n");
-    
+
     // good olde xor swap test too
     float swap_x = 100;
     float swap_y = 200;
     // good olde xor swap test too
     float swap_x = 100;
     float swap_y = 200;
@@ -63,4 +67,10 @@ void main() {
     swap_v ^= swap_u;
     swap_u ^= swap_v;
     print("'1 2 3':'4 5 6' swapped is: ", vtos(swap_u), ":", vtos(swap_v), "\n");
     swap_v ^= swap_u;
     swap_u ^= swap_v;
     print("'1 2 3':'4 5 6' swapped is: ", vtos(swap_u), ":", vtos(swap_v), "\n");
+
+    // the one that showed us overlap bugs
+    print(vtos('1 2 3' ^ f('3 2 1') ^ f('1 1 1')), "\n");
+    print(vtos('1 2 3' ^ f('3 2 1') ^ 3),          "\n");
+    print(vtos('1 2 3' ^ 6          ^ 3),          "\n");
+    print(vtos('1 2 3' ^ 6          ^ f('1 1 1')), "\n");
 }
 }
index a08d82487ef5e4105ebb984b38cc39b6328d730c..1c59af8975d4d8b1b16aad2f554a51e0de8d00b3 100644 (file)
@@ -14,3 +14,7 @@ M: vv: '6 8 6'
 M: vf: '15 8 15'
 M: 100:200 swapped is: 200:100
 M: '1 2 3':'4 5 6' swapped is: '4 5 6':'1 2 3'
 M: vf: '15 8 15'
 M: 100:200 swapped is: 200:100
 M: '1 2 3':'4 5 6' swapped is: '4 5 6':'1 2 3'
+M: '4 7 6'
+M: '4 7 6'
+M: '4 7 6'
+M: '4 7 6'