Prechádzať zdrojové kódy

changed unit tests to Google Test framework

Johannes Ruehle 9 rokov pred
rodič
commit
3cdbda98dc

+ 30 - 32
tests/TestFastHIK.cpp

@@ -1,3 +1,7 @@
+/**
+ * CppUnit-Testcase.
+ * @brief CppUnit-Testcase to verify that all important methods of the gp-hik framework perform as desired
+ */
 #ifdef NICE_USELIB_CPPUNIT
 
 #include <string>
@@ -17,7 +21,9 @@
 #include "gp-hik-core/quantization/Quantization.h"
 #include "gp-hik-core/quantization/Quantization1DAequiDist0To1.h"
 
-#include "TestFastHIK.h"
+#include <gp-hik-core/GMHIKernel.h>
+
+#include <gtest/gtest.h>
 
 const bool b_debug = false;
 const bool verbose = false;
@@ -87,15 +93,7 @@ bool compareLUTs(const double* LUT1, const double* LUT2, const int & size, const
 using namespace NICE;
 using namespace std;
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestFastHIK );
-
-void TestFastHIK::setUp() {
-}
-
-void TestFastHIK::tearDown() {
-}
-
-void TestFastHIK::testKernelMultiplication() 
+TEST(TestFastHIK,testKernelMultiplication)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelMultiplication ===================== " << std::endl;
@@ -125,7 +123,7 @@ void TestFastHIK::testKernelMultiplication()
     
   if ( (n*d)>0)
   {
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(fmk.getSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
+    ASSERT_NEAR(fmk.getSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
     if (verbose)
       std::cerr << "fmk.getSparsityRatio(): " << fmk.getSparsityRatio() << " (double)nrZeros/(double)(n*d): " << (double)nrZeros/(double)(n*d) << std::endl;
   }
@@ -169,8 +167,8 @@ void TestFastHIK::testKernelMultiplication()
     cerr << "K = " << K << endl;
 
   // check the trace calculation
-  //CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
+  //ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
+  ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
 
   // let us compute the kernel multiplication with the slow version
   Vector alpha_slow = K*y;
@@ -178,7 +176,7 @@ void TestFastHIK::testKernelMultiplication()
   if (verbose)
     std::cerr << "Sparse multiplication [alpha, alpha_slow]: " << std::endl <<  alpha << std::endl << alpha_slow << std::endl << std::endl;
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL((alpha-alpha_slow).normL1(), 0.0, 1e-8);
+  ASSERT_NEAR((alpha-alpha_slow).normL1(), 0.0, 1e-8);
 
   // test the case, where we first transform and then use the multiply stuff
   NICE::GeneralizedIntersectionKernelFunction<double> ghikSlow ( 1.2 );
@@ -193,12 +191,12 @@ void TestFastHIK::testKernelMultiplication()
 
   Vector galpha_slow = gK * y;
 
-  CPPUNIT_ASSERT_DOUBLES_EQUAL((galpha-galpha_slow).normL1(), 0.0, 1e-8);
+  ASSERT_NEAR((galpha-galpha_slow).normL1(), 0.0, 1e-8);
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelMultiplication done ===================== " << std::endl;
 }
 
-void TestFastHIK::testKernelMultiplicationFast() 
+TEST(TestFastHIK, testKernelMultiplicationFast)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelMultiplicationFast ===================== " << std::endl;
@@ -269,8 +267,8 @@ void TestFastHIK::testKernelMultiplicationFast()
     cerr << "K = " << K << endl;
 
   // check the trace calculation
-  //CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
+  //ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
+  ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
 
   // let us compute the kernel multiplication with the slow version
   Vector alpha_slow = K*y;
@@ -278,7 +276,7 @@ void TestFastHIK::testKernelMultiplicationFast()
   if ( verbose )
     std::cerr << "Sparse multiplication [alpha, alphaFast, alpha_slow]: " << std::endl <<  alpha << std::endl << alphaFast << std::endl << alpha_slow << std::endl << std::endl;
  
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, (alphaFast-alpha_slow).normL1(), 1e-8);
+  ASSERT_NEAR(0.0, (alphaFast-alpha_slow).normL1(), 1e-8);
 
   // test the case, where we first transform and then use the multiply stuff
   NICE::GeneralizedIntersectionKernelFunction<double> ghikSlow ( 1.2 );
@@ -305,13 +303,13 @@ void TestFastHIK::testKernelMultiplicationFast()
   delete q;
   
   // final assertion
-  CPPUNIT_ASSERT_DOUBLES_EQUAL((galphaFast-galpha_slow).normL1(), 0.0, 1e-8);
+  ASSERT_NEAR((galphaFast-galpha_slow).normL1(), 0.0, 1e-8);
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelMultiplicationFast done ===================== " << std::endl;
 }
 
 
-void TestFastHIK::testKernelSum() 
+TEST(TestFastHIK, testKernelSum)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelSum ===================== " << std::endl;
@@ -377,14 +375,14 @@ void TestFastHIK::testKernelSum()
 
   if (verbose)
     std::cerr << "difference of beta_slow and betaSparse: " << fabs(beta_slow - betaSparse) << std::endl;
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(beta_slow, betaSparse, 1e-8);
+  ASSERT_NEAR(beta_slow, betaSparse, 1e-8);
   
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelSum done ===================== " << std::endl;
 }
 
 
-void TestFastHIK::testKernelSumFast() 
+TEST(TestFastHIK, testKernelSumFast)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelSumFast ===================== " << std::endl;
@@ -513,7 +511,7 @@ void TestFastHIK::testKernelSumFast()
     delete [] TlookupOld;    
     
     // final assertion    
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(beta_slow, beta_fast_sparse, 1e-8);
+    ASSERT_NEAR(beta_slow, beta_fast_sparse, 1e-8);
   
 
   } // for-loop
@@ -526,7 +524,7 @@ void TestFastHIK::testKernelSumFast()
 
 }
 
-void TestFastHIK::testLUTUpdate()
+TEST(TestFastHIK, testLUTUpdate)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testLUTUpdate ===================== " << std::endl;
@@ -657,14 +655,14 @@ void TestFastHIK::testLUTUpdate()
   delete [] TNew;  
     
   // final assertion        
-  CPPUNIT_ASSERT(equal == true);
+  ASSERT_TRUE(equal == true);
   
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testLUTUpdate done ===================== " << std::endl;
 
 }
 
-void TestFastHIK::testLinSolve()
+TEST(TestFastHIK, testLinSolve)
 {
 
   if (verboseStartEnd)
@@ -771,13 +769,13 @@ void TestFastHIK::testLinSolve()
   delete pf;
     
   // final assertion        
-  CPPUNIT_ASSERT_DOUBLES_EQUAL((K_alphaRandomized-y).normL1(), 0.0, 1e-6);
+  ASSERT_NEAR((K_alphaRandomized-y).normL1(), 0.0, 1e-6);
   
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testLinSolve done ===================== " << std::endl;
 }
 
-void TestFastHIK::testKernelVector()
+TEST(TestFastHIK, testKernelVector)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestFastHIK::testKernelVector ===================== " << std::endl;  
@@ -833,8 +831,8 @@ void TestFastHIK::testKernelVector()
     
   for (int i = 0; i < 5; i++)
   {
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(k1[i]-k1GT[i], 0.0, 1e-6);
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(k2[i]-k2GT[i], 0.0, 1e-6);
+    ASSERT_NEAR(k1[i]-k1GT[i], 0.0, 1e-6);
+    ASSERT_NEAR(k2[i]-k2GT[i], 0.0, 1e-6);
   }
 
   
@@ -843,4 +841,4 @@ void TestFastHIK::testKernelVector()
   
 }
 
-#endif
+#endif

+ 0 - 44
tests/TestFastHIK.h

@@ -1,44 +0,0 @@
-#ifndef _TESTFASTHIK_H
-#define _TESTFASTHIK_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/GMHIKernel.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that all important methods of the gp-hik framework perform as desired
- */
-class TestFastHIK : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestFastHIK );
-    
-    CPPUNIT_TEST(testKernelMultiplication);
-    CPPUNIT_TEST(testKernelMultiplicationFast);
-    CPPUNIT_TEST(testKernelSum);
-    CPPUNIT_TEST(testKernelSumFast);
-    CPPUNIT_TEST(testLUTUpdate);
-    CPPUNIT_TEST(testLinSolve);
-    CPPUNIT_TEST(testKernelVector);
-    
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
- 
- public:
-    void setUp();
-    void tearDown();
-
-    /**
-    * Constructor / Destructor testing 
-    */  
-    void testKernelMultiplication();
-    void testKernelMultiplicationFast();
-    void testKernelSum();
-    void testKernelSumFast();
-    void testLUTUpdate();
-    void testLinSolve();
-    void testKernelVector();
-
-};
-
-#endif // _TESTFASTHIK_H

+ 10 - 13
tests/TestFeatureMatrixT.cpp

@@ -1,3 +1,7 @@
+/**
+ * CppUnit-Testcase.
+ * @brief CppUnit-Testcase to verify that all important methods of the Feature Matrix perform as desired
+ */
 #ifdef NICE_USELIB_CPPUNIT
 
 #include <string>
@@ -6,8 +10,9 @@
 #include <core/matlabAccess/MatFileIO.h>
 
 #include <gp-hik-core/tools.h>
+#include <gp-hik-core/FeatureMatrixT.h>
 
-#include "TestFeatureMatrixT.h"
+#include <gtest/gtest.h>
 
 const bool verbose = false;
 const bool verboseStartEnd = true;
@@ -18,15 +23,7 @@ const double sparse_prob = 0.8;
 using namespace NICE;
 using namespace std;
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestFeatureMatrixT );
-
-void TestFeatureMatrixT::setUp() {
-}
-
-void TestFeatureMatrixT::tearDown() {
-}
-
-void TestFeatureMatrixT::testSetup()
+TEST(TestFeatureMatrixT,testSetup)
 {
   
   if (verboseStartEnd)
@@ -60,7 +57,7 @@ void TestFeatureMatrixT::testSetup()
   {
   if (verbose)
     std::cerr << "fm.computeSparsityRatio(): " << fm.computeSparsityRatio() << " (double)nrZeros/(double)(n*d): " << (double)nrZeros/(double)(n*d) << std::endl;
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(fm.computeSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
+  ASSERT_NEAR(fm.computeSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
   }
   
   transposeVectorOfVectors(dataMatrix);
@@ -72,7 +69,7 @@ void TestFeatureMatrixT::testSetup()
   {
   if (verbose)
     std::cerr << "fm.computeSparsityRatio(): " << fm.computeSparsityRatio() << " (double)nrZeros/(double)(n*d): " << (double)nrZeros/(double)(n*d) << std::endl;
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(fm.computeSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
+  ASSERT_NEAR(fm.computeSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
   }
   
   NICE::MatrixT<double> matNICE;
@@ -98,7 +95,7 @@ void TestFeatureMatrixT::testSetup()
 }
 
 
-void TestFeatureMatrixT::testMatlabIO()
+TEST(TestFeatureMatrixT,testMatlabIO)
 {
   
   if (verboseStartEnd)

+ 0 - 32
tests/TestFeatureMatrixT.h

@@ -1,32 +0,0 @@
-#ifndef _TESTFEATUREMATRIXT_H
-#define _TESTFEATUREMATRIXT_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/FeatureMatrixT.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that all important methods of the Feature Matrix perform as desired
- */
-class TestFeatureMatrixT : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestFeatureMatrixT );
-	 CPPUNIT_TEST(testSetup);
-	 CPPUNIT_TEST(testMatlabIO);
-      
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
- 
- public:
-    void setUp();
-    void tearDown();
-
-    /**
-    * Constructor / Destructor testing 
-    */  
-		void testSetup();
-		void testMatlabIO();
-};
-
-#endif // _TESTFEATUREMATRIXT_H

+ 16 - 28
tests/TestGPHIKOnlineLearnable.cpp

@@ -1,10 +1,9 @@
-/** 
- * @file TestGPHIKOnlineLearnable.cpp
- * @brief CppUnit-Testcase to verify that GPHIKClassifier methods herited from Persistent (store and restore) work as desired.
+/**
+ * CppUnit-Testcase.
+ * @brief CppUnit-Testcase to verify that GPHIKClassifierIL methods herited from OnlineLearnable (addExample and addMultipleExamples) work as desired.
  * @author Alexander Freytag
- * @date 21-12-2013
-*/
-
+ * @date 03-01-2014 (dd-mm-yyyy)
+ */
 #ifdef NICE_USELIB_CPPUNIT
 
 // STL includes
@@ -18,7 +17,7 @@
 // gp-hik-core includes
 #include "gp-hik-core/GPHIKClassifier.h"
 
-#include "TestGPHIKOnlineLearnable.h"
+#include <gtest/gtest.h>
 
 using namespace std; //C basics
 using namespace NICE;  // nice-core
@@ -27,17 +26,6 @@ const bool verboseStartEnd = true;
 const bool verbose = false;
 const bool writeClassifiersForVerification = false;
 
-
-CPPUNIT_TEST_SUITE_REGISTRATION( TestGPHIKOnlineLearnable );
-
-void TestGPHIKOnlineLearnable::setUp() {
-}
-
-void TestGPHIKOnlineLearnable::tearDown() {
-}
-
-
-
 void readData ( const std::string filename, NICE::Matrix & data, NICE::Vector & yBin, NICE::Vector & yMulti )
 {
  std::ifstream ifs ( filename.c_str() , ios::in );
@@ -52,7 +40,7 @@ void readData ( const std::string filename, NICE::Matrix & data, NICE::Vector &
   else 
   {
     std::cerr << "Unable to read data from file " << filename << " -- aborting." << std::endl;
-    CPPUNIT_ASSERT ( ifs.good() );
+    ASSERT_TRUE( ifs.good() );
   }    
 }
 
@@ -152,11 +140,11 @@ void compareClassifierOutputs ( const NICE::GPHIKClassifier * classifier,
       }        
     }
     
-    CPPUNIT_ASSERT_EQUAL ( equal, true );     
+    ASSERT_EQ( equal, true );     
   }  
 }
 
-void TestGPHIKOnlineLearnable::testOnlineLearningStartEmpty()
+TEST(TestGPHIKOnlineLearnable,testOnlineLearningStartEmpty)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningStartEmpty ===================== " << std::endl;  
@@ -253,7 +241,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningStartEmpty()
   }  
 
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrScratch, 1e-8);
+  ASSERT_NEAR( arr, arrScratch, 1e-8);
   
   // don't waste memory
   
@@ -270,7 +258,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningStartEmpty()
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningStartEmpty done ===================== " << std::endl;   
 }
 
-void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
+TEST(TestGPHIKOnlineLearnable, testOnlineLearningOCCtoBinary)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary ===================== " << std::endl;  
@@ -390,7 +378,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
     std::cerr << "confusionMatrixScratch: " << confusionMatrixScratch << std::endl;
   } 
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrScratch, 1e-8);
+  ASSERT_NEAR( arr, arrScratch, 1e-8);
   
   // don't waste memory
   
@@ -406,7 +394,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary done ===================== " << std::endl;   
 }
 
-void TestGPHIKOnlineLearnable::testOnlineLearningBinarytoMultiClass()
+TEST(TestGPHIKOnlineLearnable, testOnlineLearningBinarytoMultiClass)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningBinarytoMultiClass ===================== " << std::endl;   
@@ -532,7 +520,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningBinarytoMultiClass()
   }
 
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrScratch, 1e-8);
+  ASSERT_NEAR( arr, arrScratch, 1e-8);
   
   // don't waste memory
   
@@ -549,7 +537,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningBinarytoMultiClass()
     std::cerr << "================== TestGPHIKOnlineLearnable::testOnlineLearningBinarytoMultiClass done ===================== " << std::endl;   
 }
 
-void TestGPHIKOnlineLearnable::testOnlineLearningMultiClass()
+TEST(TestGPHIKOnlineLearnable, testOnlineLearningMultiClass)
 {
   
   if (verboseStartEnd)
@@ -688,7 +676,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningMultiClass()
   }
   
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrScratch, 1e-8);
+  ASSERT_NEAR( arr, arrScratch, 1e-8);
   
   // don't waste memory
   

+ 0 - 38
tests/TestGPHIKOnlineLearnable.h

@@ -1,38 +0,0 @@
-#ifndef _TESTGPHIKONLINELEARNABLE_H
-#define _TESTGPHIKONLINELEARNABLE_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/GPHIKClassifier.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that GPHIKClassifierIL methods herited from OnlineLearnable (addExample and addMultipleExamples) work as desired.
- * @author Alexander Freytag
- * @date 03-01-2014 (dd-mm-yyyy)
- */
-class TestGPHIKOnlineLearnable : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestGPHIKOnlineLearnable );
-      CPPUNIT_TEST(testOnlineLearningStartEmpty);
-      CPPUNIT_TEST(testOnlineLearningOCCtoBinary);
-      CPPUNIT_TEST(testOnlineLearningBinarytoMultiClass);
-      CPPUNIT_TEST(testOnlineLearningMultiClass);
-      
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
- 
- public:
-    void setUp();
-    void tearDown();
-
-    void testOnlineLearningStartEmpty();    
-    
-    void testOnlineLearningOCCtoBinary();
-    
-    void testOnlineLearningBinarytoMultiClass();
-
-    void testOnlineLearningMultiClass();
-};
-
-#endif // _TESTGPHIKONLINELEARNABLE_H

+ 6 - 13
tests/TestGPHIKPersistent.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file TestGPHIKPersistent.cpp
  * @brief CppUnit-Testcase to verify that GPHIKClassifier methods herited from Persistent (store and restore) work as desired.
  * @author Alexander Freytag
@@ -18,7 +18,7 @@
 // gp-hik-core includes
 #include "gp-hik-core/GPHIKClassifier.h"
 
-#include "TestGPHIKPersistent.h"
+#include <gtest/gtest.h>
 
 using namespace std; //C basics
 using namespace NICE;  // nice-core
@@ -27,14 +27,7 @@ const bool verboseStartEnd = true;
 const bool verbose = false;
 
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestGPHIKPersistent );
-
-void TestGPHIKPersistent::setUp() {
-}
-
-void TestGPHIKPersistent::tearDown() {
-}
-void TestGPHIKPersistent::testPersistentMethods()
+TEST(TestGPHIKPersistent, testPersistentMethods)
 {
   
   if (verboseStartEnd)
@@ -62,7 +55,7 @@ void TestGPHIKPersistent::testPersistentMethods()
   else 
   {
     std::cerr << "Unable to read training data from file " << trainData << " -- aborting." << std::endl;
-    CPPUNIT_ASSERT ( ifsTrain.good() );
+    ASSERT_TRUE( ifsTrain.good() );
   } 
   
   //----------------- convert data to sparse data structures ---------
@@ -153,7 +146,7 @@ void TestGPHIKPersistent::testPersistentMethods()
   else 
   {
     std::cerr << "Unable to read test data, aborting." << std::endl;
-    CPPUNIT_ASSERT ( ifsTest.good() );
+    ASSERT_TRUE( ifsTest.good() );
   }
   
   // ------------------------------------------
@@ -251,7 +244,7 @@ void TestGPHIKPersistent::testPersistentMethods()
   }
 
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrRestored, 1e-8);
+  ASSERT_NEAR( arr, arrRestored, 1e-8);
   
   // don't waste memory
   //TODO clean up of training data, also in TestGPHIKPersistent

+ 0 - 30
tests/TestGPHIKPersistent.h

@@ -1,30 +0,0 @@
-#ifndef _TESTGPHIKPERSISTENT_H
-#define _TESTGPHIKPERSISTENT_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/GPHIKClassifier.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that GPHIKClassifier methods herited from Persistent (store and restore) work as desired.
- * @author Alexander Freytag
- * @date 21-12-2013
- */
-class TestGPHIKPersistent : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestGPHIKPersistent );
-	 CPPUNIT_TEST(testPersistentMethods);
-      
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
- 
- public:
-    void setUp();
-    void tearDown();
-
-
-    void testPersistentMethods();
-};
-
-#endif // _TESTGPHIKPERSISTENT_H

+ 10 - 20
tests/TestGPHIKRegression.cpp

@@ -18,7 +18,7 @@
 // gp-hik-core includes
 #include "gp-hik-core/GPHIKRegression.h"
 
-#include "TestGPHIKRegression.h"
+#include <gtest/gtest.h>
 
 using namespace std; //C basics
 using namespace NICE;  // nice-core
@@ -27,16 +27,6 @@ const bool verboseStartEnd = true;
 const bool verbose = false;
 const bool writeRegressionObjectsForVerification = false;
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestGPHIKRegression );
-
-void TestGPHIKRegression::setUp() {
-}
-
-void TestGPHIKRegression::tearDown() {
-}
-
-
-
 void readData ( const std::string filename, NICE::Matrix & data, NICE::Vector & yValues )
 {
  std::ifstream ifs ( filename.c_str() , ios::in );
@@ -52,7 +42,7 @@ void readData ( const std::string filename, NICE::Matrix & data, NICE::Vector &
   else 
   {
     std::cerr << "Unable to read data from file " << filename << " -- aborting." << std::endl;
-    CPPUNIT_ASSERT ( ifs.good() );
+    ASSERT_TRUE( ifs.good() );
   }    
 }
 
@@ -82,7 +72,7 @@ void evaluateRegressionMethod ( double & regressionLoss,
   }
 }
 
-void TestGPHIKRegression::testRegressionHoldInData()
+TEST(TestGPHIKRegression, testRegressionHoldInData)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKRegression::testRegressionHoldInData ===================== " << std::endl;  
@@ -138,7 +128,7 @@ void TestGPHIKRegression::testRegressionHoldInData()
   }  
 
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, holdInLoss, 1e-8);
+  ASSERT_NEAR( 0.0, holdInLoss, 1e-8);
   
   // don't waste memory
   
@@ -154,7 +144,7 @@ void TestGPHIKRegression::testRegressionHoldInData()
     std::cerr << "================== TestGPHIKRegression::testRegressionHoldInData done ===================== " << std::endl;   
 }
 
-void TestGPHIKRegression::testRegressionHoldOutData()
+TEST(TestGPHIKRegression, testRegressionHoldOutData)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKRegression::testRegressionHoldOutData ===================== " << std::endl;  
@@ -216,7 +206,7 @@ void TestGPHIKRegression::testRegressionHoldOutData()
     std::cerr << " holdOutLoss: " << holdOutLoss << " accepting: " << pow(diffOkay,2)*yValuesTest.size() << std::endl;
   }  
   
-  CPPUNIT_ASSERT( pow(diffOkay,2)*yValuesTest.size() - holdOutLoss > 0.0);
+  ASSERT_TRUE( pow(diffOkay,2)*yValuesTest.size() - holdOutLoss > 0.0);
   
   // don't waste memory
   
@@ -231,7 +221,7 @@ void TestGPHIKRegression::testRegressionHoldOutData()
     std::cerr << "================== TestGPHIKRegression::testRegressionHoldOutData done ===================== " << std::endl;     
 }
     
-void TestGPHIKRegression::testRegressionOnlineLearnableAdd1Example()
+TEST(TestGPHIKRegression, testRegressionOnlineLearnableAdd1Example)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKRegression::testRegressionOnlineLearnableAdd1Example ===================== " << std::endl;  
@@ -353,7 +343,7 @@ void TestGPHIKRegression::testRegressionOnlineLearnableAdd1Example()
   }
   
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( holdOutLossIL, holdOutLossScratch, 1e-4);
+  ASSERT_NEAR( holdOutLossIL, holdOutLossScratch, 1e-4);
   
   // don't waste memory
   
@@ -370,7 +360,7 @@ void TestGPHIKRegression::testRegressionOnlineLearnableAdd1Example()
     std::cerr << "================== TestGPHIKRegression::testRegressionOnlineLearnableAdd1Example done ===================== " << std::endl;   
 }
 
-void TestGPHIKRegression::testRegressionOnlineLearnableAddMultipleExamples()
+TEST(TestGPHIKRegression, testRegressionOnlineLearnableAddMultipleExamples)
 {
   if (verboseStartEnd)
     std::cerr << "================== TestGPHIKRegression::testRegressionOnlineLearnableAddMultipleExamples ===================== " << std::endl;  
@@ -516,7 +506,7 @@ void TestGPHIKRegression::testRegressionOnlineLearnableAddMultipleExamples()
   }
   
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( holdOutLossIL, holdOutLossScratch, 1e-4);
+  ASSERT_NEAR( holdOutLossIL, holdOutLossScratch, 1e-4);
   
   // don't waste memory
   

+ 0 - 37
tests/TestGPHIKRegression.h

@@ -1,37 +0,0 @@
-#ifndef _TESTGPHIKREGRESSION_H
-#define _TESTGPHIKREGRESSION_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/GPHIKRegression.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that GPHIKRegression works as desired.
- * @author Alexander Freytag
- * @date 16-01-2014 (dd-mm-yyyy)
- */
-class TestGPHIKRegression : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestGPHIKRegression );
-      CPPUNIT_TEST(testRegressionHoldInData);
-      CPPUNIT_TEST(testRegressionHoldOutData);
-      
-      CPPUNIT_TEST(testRegressionOnlineLearnableAdd1Example);
-      CPPUNIT_TEST(testRegressionOnlineLearnableAddMultipleExamples);
-      
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
- 
- public:
-    void setUp();
-    void tearDown();
-
-    void testRegressionHoldInData();
-    void testRegressionHoldOutData();    
-    
-    void testRegressionOnlineLearnableAdd1Example();
-    void testRegressionOnlineLearnableAddMultipleExamples();    
-};
-
-#endif // _TESTGPHIKREGRESSION_H

+ 16 - 23
tests/TestVectorSorter.cpp

@@ -5,23 +5,16 @@
 #include <map>
 
 #include <gp-hik-core/SortedVectorSparse.h>
-#include "TestVectorSorter.h"
+#include <gp-hik-core/GMHIKernel.h>
 
+#include <gtest/gtest.h>
 
 using namespace NICE;
 using namespace std;
 
 const bool verboseStartEnd = true;
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestVectorSorter );
-
-void TestVectorSorter::setUp() {
-}
-
-void TestVectorSorter::tearDown() {
-}
-
-void TestVectorSorter::checkData ( const vector<double> & all_elements, const NICE::SortedVectorSparse<double> & vSS, double sparse_tolerance )
+void checkData ( const vector<double> & all_elements, const NICE::SortedVectorSparse<double> & vSS, double sparse_tolerance = 1e-7 )
 {
   
   if (verboseStartEnd)
@@ -47,30 +40,30 @@ void TestVectorSorter::checkData ( const vector<double> & all_elements, const NI
   uint k = 0;
   for (NICE::SortedVectorSparse<double>::const_elementpointer it = vSS.nonzeroElements().begin(); it != vSS.nonzeroElements().end(); it++,k++)
   {
-    CPPUNIT_ASSERT_DOUBLES_EQUAL( nonzero_elements[k].first, it->first, 0.0 );
-    CPPUNIT_ASSERT_EQUAL( nonzero_elements[k].second, it->second.first );
+    ASSERT_NEAR( nonzero_elements[k].first, it->first, 0.0 );
+    ASSERT_EQ( nonzero_elements[k].second, it->second.first );
   }
 
   // 2 3 0 1 5 4
 	std::vector<uint> vSSPerm(vSS.getPermutation());
 	for ( uint k = 0;k < vSSPerm.size(); k++ )
 	{
-    CPPUNIT_ASSERT_EQUAL( all_elements_sorted[k].second, vSSPerm[k] );
+    ASSERT_EQ( all_elements_sorted[k].second, vSSPerm[k] );
 	}
 	
   std::vector<uint> vSSPermNNZ (vSS.getPermutationNonZero());
   vector<pair<uint,double> > sv ( vSS.getOrderInSeparateVector() );
   for ( int k = 0;k < vSSPermNNZ.size(); k++ )
   {
-    CPPUNIT_ASSERT_EQUAL( nonzero_elements[k].second, vSSPermNNZ[k] );
-    CPPUNIT_ASSERT_EQUAL( sv[k].first, vSSPermNNZ[k] );
-    CPPUNIT_ASSERT_EQUAL( sv[k].second, vSS.access( sv[k].first ) );
+    ASSERT_EQ( nonzero_elements[k].second, vSSPermNNZ[k] );
+    ASSERT_EQ( sv[k].first, vSSPermNNZ[k] );
+    ASSERT_EQ( sv[k].second, vSS.access( sv[k].first ) );
   }
 
 
   for ( uint k = 0;k < vSS.getN();k++ )
   {
-    CPPUNIT_ASSERT_DOUBLES_EQUAL( all_elements[k], vSS.access(k), sparse_tolerance ); 
+    ASSERT_NEAR( all_elements[k], vSS.access(k), sparse_tolerance ); 
   }
 
   if (verboseStartEnd)
@@ -78,7 +71,7 @@ void TestVectorSorter::checkData ( const vector<double> & all_elements, const NI
 
 }
 
-void TestVectorSorter::testVectorSorter() 
+TEST(TestVectorSorter,testVectorSorter)
 {
   
   if (verboseStartEnd)
@@ -165,7 +158,7 @@ void TestVectorSorter::testVectorSorter()
     std::cerr << "================== TestVectorSorter::testVectorSorter done ===================== " << std::endl;  
 }
 
-void TestVectorSorter::testMultiMap()
+TEST(TestVectorSorter,testMultiMap)
 {
   
   if (verboseStartEnd)
@@ -178,10 +171,10 @@ void TestVectorSorter::testMultiMap()
   multimap<int, double>::iterator it4 = d.insert ( pair<int, double> ( 5, 5.0 ) );
 
   it1->second = 1.5;
-  CPPUNIT_ASSERT_EQUAL ( 1.5, it1->second );
-  CPPUNIT_ASSERT_EQUAL ( 1.0, it2->second );
-  CPPUNIT_ASSERT_EQUAL ( 2.0, it3->second );
-  CPPUNIT_ASSERT_EQUAL ( 5.0, it4->second );
+  ASSERT_EQ( 1.5, it1->second );
+  ASSERT_EQ( 1.0, it2->second );
+  ASSERT_EQ( 2.0, it3->second );
+  ASSERT_EQ( 5.0, it4->second );
   
   if (verboseStartEnd)
     std::cerr << "================== TestVectorSorter::testMultiMap done ===================== " << std::endl;  

+ 0 - 36
tests/TestVectorSorter.h

@@ -1,36 +0,0 @@
-#ifndef _TESTVECTORSORTER_H
-#define _TESTVECTORSORTER_H
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <gp-hik-core/GMHIKernel.h>
-
-/**
- * CppUnit-Testcase. 
- * @brief CppUnit-Testcase to verify that all important methods of the SortedVectorSparse class perform as desired
- */
-class TestVectorSorter : public CppUnit::TestFixture {
-
-    CPPUNIT_TEST_SUITE( TestVectorSorter );
-    
-    CPPUNIT_TEST(testVectorSorter);
-    CPPUNIT_TEST(testMultiMap);
-    
-    CPPUNIT_TEST_SUITE_END();
-  
- private:
-    void checkData ( const std::vector<double> & all_elements, const NICE::SortedVectorSparse<double> & vSS, double sparse_tolerance = 1e-7 );
- 
- public:
-    void setUp();
-    void tearDown();
-
-    /**
-    * Constructor / Destructor testing 
-    */  
-    void testVectorSorter();
-
-    void testMultiMap();
-
-};
-
-#endif // _TESTFASTHIK_H