[opengtl-commits] [237] * TestFramework : add functions to test for vectors equality and matrix equality

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 237
Author:   cyrille
Date:     2008-06-26 22:09:43 +0200 (Thu, 26 Jun 2008)

Log Message:
-----------
* TestFramework : add functions to test for vectors equality and matrix equality
* complextypes :
 - test for array copy
 - test for returning array and structures
* test vectors and matrixes operations
* test for "<=" of signed integers

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/tests/TestFramework.ctl
    trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt
    trunk/OpenGTL/OpenCTL/tests/statements/for.ctl
    trunk/OpenGTL/OpenCTL/tests/stdlib/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenCTL/tests/complextypes/copyarray.ctl
    trunk/OpenGTL/OpenCTL/tests/complextypes/returnarray.ctl
    trunk/OpenGTL/OpenCTL/tests/complextypes/returnstruct.ctl
    trunk/OpenGTL/OpenCTL/tests/stdlib/vecmatop.ctl


Modified: trunk/OpenGTL/OpenCTL/tests/TestFramework.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/TestFramework.ctl	2008-06-26 20:04:22 UTC (rev 236)
+++ trunk/OpenGTL/OpenCTL/tests/TestFramework.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -15,6 +15,39 @@
       ++errorcount;
     }
   }
+  void checkNearEqualVec( float f1[3], float f2[3], output int errorcount)
+  {
+    for( int k = 0; k < 3; ++k)
+    {
+      float diff = f1[k] - f2[k];
+      if( diff > 10e-3 || (-diff > 10e-3))
+      {
+        print(k, f1[k], f2[k], diff);
+        ++errorcount;
+      }
+    }
+  }
+  void checkNearEqualMat( float f1[][], float f2[][], output int errorcount)
+  {
+    for( int i = 0; i < f1.size; ++i)
+    {
+      if( f1[i].size == f2[i].size )
+      {
+        for( int j = 0; j < f1[i].size; ++j )
+        {
+          float diff = f1[i][j] - f2[i][j];
+          if( diff > 10e-3 || (-diff > 10e-3))
+          {
+            print(i, j, f1[i][j], f2[i][j], diff);
+            ++errorcount;
+          }
+        }
+      } else {
+        print( i, " different size ", f1[i].size, f2[i].size );
+        ++errorcount;
+      }
+    }
+  }
   void checkNearEqual( float f1, float f2, output int errorcount)
   {
     float diff = f1 - f2;

Modified: trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt	2008-06-26 20:04:22 UTC (rev 236)
+++ trunk/OpenGTL/OpenCTL/tests/complextypes/CMakeLists.txt	2008-06-26 20:09:43 UTC (rev 237)
@@ -14,6 +14,9 @@
   structarrayarraysimplecoumpoundinitialiser.ctl
   structfunctioncoumpoundinitialisation.ctl
   copystruct.ctl
+  copyarray.ctl
+  returnstruct.ctl
+  returnarray.ctl
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )

Added: trunk/OpenGTL/OpenCTL/tests/complextypes/copyarray.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/complextypes/copyarray.ctl	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/tests/complextypes/copyarray.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -0,0 +1,19 @@
+import "TestFramework";
+
+int main()
+{
+  int m[3];
+  m[0] = 10;
+  m[1] = 5;
+  m[2] = -3;
+  int m2[3];
+  m2 = m;
+  int errorcount = 0;
+  Test::checkIntEqual( m[0], 10, errorcount );
+  Test::checkIntEqual( m[1], 5, errorcount );
+  Test::checkIntEqual( m[2], -3, errorcount );
+  Test::checkIntEqual( m2[0], 10, errorcount );
+  Test::checkIntEqual( m2[1], 5, errorcount );
+  Test::checkIntEqual( m2[2], -3, errorcount );
+  return errorcount;
+}

Added: trunk/OpenGTL/OpenCTL/tests/complextypes/returnarray.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/complextypes/returnarray.ctl	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/tests/complextypes/returnarray.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -0,0 +1,34 @@
+
+import "TestFramework";
+
+int[3] returnArray()
+{
+  int a[3];
+  a[0] = -1;
+  a[1] = 2;
+  a[2] = 3;
+  int b[3];
+  if( false )
+  {
+    return b;
+  }
+  return a;
+}
+
+int main()
+{
+  int errorcount = 0;
+  {
+    int arr[3] = returnArray();
+    Test::checkIntEqual( arr[0], -1, errorcount );
+    Test::checkIntEqual( arr[1], 2, errorcount );
+    Test::checkIntEqual( arr[2], 3, errorcount );
+  }
+  {
+    int arr[] = returnArray();
+    Test::checkIntEqual( arr[0], -1, errorcount );
+    Test::checkIntEqual( arr[1], 2, errorcount );
+    Test::checkIntEqual( arr[2], 3, errorcount );
+  }
+  return errorcount;
+}

Added: trunk/OpenGTL/OpenCTL/tests/complextypes/returnstruct.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/complextypes/returnstruct.ctl	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/tests/complextypes/returnstruct.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -0,0 +1,27 @@
+
+import "TestFramework";
+
+struct MyStruct {
+  int i;
+  bool b;
+  float f;
+};
+
+MyStruct returnStruct()
+{
+  MyStruct a;
+  a.i = -1;
+  a.b = true;
+  a.f = 12.42;
+  return a;
+}
+
+int main()
+{
+  int errorcount = 0;
+  MyStruct ms = returnStruct();
+  Test::checkIntEqual( ms.i, -1, errorcount );
+  Test::checkIntEqual( ms.b, true, errorcount );
+  Test::checkIntEqual( ms.f, 12.42, errorcount );
+  return errorcount;
+}

Modified: trunk/OpenGTL/OpenCTL/tests/statements/for.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/statements/for.ctl	2008-06-26 20:04:22 UTC (rev 236)
+++ trunk/OpenGTL/OpenCTL/tests/statements/for.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -6,6 +6,14 @@
   {
     ++j;
   }
-  assert(j == 10);
+  for( int i = 10; i >= 0; --i)
+  {
+    ++j;
+    if( j > 30 )
+    {
+      return 1;
+    }
+  }
+  assert(j == 21);
   return 0;
 }

Modified: trunk/OpenGTL/OpenCTL/tests/stdlib/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/stdlib/CMakeLists.txt	2008-06-26 20:04:22 UTC (rev 236)
+++ trunk/OpenGTL/OpenCTL/tests/stdlib/CMakeLists.txt	2008-06-26 20:09:43 UTC (rev 237)
@@ -8,6 +8,7 @@
   powers.ctl
   lookup.ctl
   interpolate.ctl
+  vecmatop.ctl
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )

Added: trunk/OpenGTL/OpenCTL/tests/stdlib/vecmatop.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/stdlib/vecmatop.ctl	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/tests/stdlib/vecmatop.ctl	2008-06-26 20:09:43 UTC (rev 237)
@@ -0,0 +1,45 @@
+import "TestFramework";
+
+int main()
+{
+  int errorcount = 0;
+  // Data
+  float x[3] = { 1, 2 ,3 };
+  float y[3] = { 4, 5, 6 };
+  float A[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
+  float B[3][3] = { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } };
+  float C[4][4] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } };
+  float D[4][4] = { { 17, 18, 19, 20 }, { 21, 22, 23, 24}, { 25, 26, 27, 28 }, { 29, 30, 31, 32} };
+  
+  float E[3][3] = { { 2, 2, 2 }, { 2, 0, 2 }, { 0, 1, 2 } };
+  float F[4][4] = { { 2, 2, 2, 2 }, { 2, 0, 2, 0 }, { 0, 1, 2,0 }, {1, 0, 0, 2} };
+  
+  // Test vectors
+  Test::checkNearEqualVec( mult_f_f3( 1.5, x ), { 1.5, 3.0, 4.5 }, errorcount );
+  Test::checkNearEqualVec( add_f3_f3( x, y ), { 5, 7, 9 }, errorcount );
+  Test::checkNearEqualVec( sub_f3_f3( x, y ), { -3, -3, -3 }, errorcount );
+  Test::checkNearEqualVec( cross_f3_f3( x, y ), { -3, 6, -3 }, errorcount );
+  Test::checkNearEqual( dot_f3_f3( x, y ), 32, errorcount );
+  Test::checkNearEqual( length_f3( x ), 3.74166, errorcount );
+  Test::checkNearEqual( length_f3( y ), 8.77496, errorcount );
+  
+  // Test matrixes
+  Test::checkNearEqualMat( mult_f_f33( 1.5, A), { { 1.5, 3.0, 4.5 }, { 6, 7.5, 9 }, { 10.5, 12, 13.5 } }, errorcount);
+  Test::checkNearEqualMat( mult_f_f44( 2.0, C), { { 2, 4, 6, 8 }, { 10, 12, 14, 16 }, { 18, 20, 22, 24 }, { 26, 28, 30, 32 } }, errorcount);
+  Test::checkNearEqualMat( add_f33_f33( A, B), { { 11, 13, 15 }, { 17, 19, 21 }, { 23, 25, 27 } }, errorcount);
+  Test::checkNearEqualMat( add_f44_f44( C, D), { { 18, 20, 22, 24 }, { 26, 28, 30, 32 }, { 34, 36, 38, 40 }, { 42, 44, 46, 48 } }, errorcount);
+  
+  Test::checkNearEqualMat( mult_f33_f33(A,B), { { 84, 90, 96 }, { 201, 216, 231 }, { 318, 342, 366} }, errorcount );
+  Test::checkNearEqualMat( mult_f44_f44(C,D), { { 250, 260, 270, 280 }, { 618, 644, 670, 696 }, { 986, 1028, 1070, 1112 }, { 1354, 1412, 1470, 1528 } }, errorcount );
+
+  Test::checkNearEqualMat( invert_f33(E), { { 0.25, 0.25, -0.5 }, { 0.5, -0.5, 0.0 }, {-0.25, 0.25, 0.5 } }, errorcount );
+  Test::checkNearEqualMat( invert_f44(F), { { 0.33333, 0.33333, -0.66667, -0.33333 }, {0.66667,-0.33333, -0.33333, -0.66667}, {-0.33333, 0.16667, 0.66667, 0.33333 }, {-0.16667, -0.16667, 0.33333, 0.66667 } }, errorcount );
+  
+  // Test vectors+matrixes
+  Test::checkNearEqualVec( mult_f3_f33( x, A ), { 30, 36, 42 }, errorcount );
+  Test::checkNearEqualVec( mult_f3_f44( x, C ), {  0.70833, 0.80556, 0.90278 }, errorcount );
+  
+  
+  
+  return errorcount;
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/