Преглед изворни кода

fixed tests for cross compilation

Johannes R пре 12 година
родитељ
комит
b1881a89ac

+ 12 - 0
core/algebra/tests/TestDiagApprox.cpp

@@ -37,7 +37,11 @@ void TestDiagApprox::TestDiagApproxComputation()
     uint maxiterations =  20;
    
    // use a fixed seed, its a test case
+#ifdef WIN32
+	srand(0);
+#else
     srand48(0);
+#endif
  
     DiagonalMatrixApprox diagApprox ( true /*verbose*/ );
     
@@ -47,7 +51,11 @@ void TestDiagApprox::TestDiagApproxComputation()
    
     for (uint j = 0 ; j < rows ; j++)
     {
+#ifdef WIN32
+		 Tdiag(j, j) = double( rand() ) / RAND_MAX;
+#else
       Tdiag(j, j) = drand48();
+#endif
     }
  
     diagApprox.approx ( Tdiag, D );
@@ -70,7 +78,11 @@ void TestDiagApprox::TestDiagApproxComputation()
     for (uint i = 0 ; i < rows ; i++)
         for (uint j = i ; j < cols ; j++)
         {
+#ifdef WIN32
+		 T(i, j) = double( rand() ) / RAND_MAX;
+#else
             T(i, j) = drand48();
+#endif
             T(j, i) = T(i, j);
         }
 

+ 11 - 0
core/algebra/tests/TestEigenValue.cpp

@@ -48,16 +48,27 @@ void TestEigenValue::TestEigenValueComputation()
     NICE::Matrix T(rows, cols, 0.0);
 
     // use a fixed seed, its a test case
+#ifdef WIN32
+	srand(0);
+#else
     srand48(0);
+#endif
 
     // generate random symmetric matrix
     for (uint i = 0 ; i < rows ; i++)
         for (uint j = i ; j < cols ; j++)
         {
+#ifdef WIN32
+            if (sparse_prob != 0.0)
+                if ( double( rand() ) / RAND_MAX < sparse_prob)
+                    continue;
+            T(i, j) = double( rand() ) / RAND_MAX;
+#else
             if (sparse_prob != 0.0)
                 if (drand48() < sparse_prob)
                     continue;
             T(i, j) = drand48();
+#endif
             T(j, i) = T(i, j);
         }
 

+ 16 - 0
core/algebra/tests/TestLinearSolve.cpp

@@ -51,16 +51,28 @@ void TestLinearSolve::TestLinearSolveComputation()
     NICE::Matrix T(rows, cols, 0.0);
 
     // use a fixed seed, its a test case
+#ifdef WIN32
+	srand(0);
+#else
     srand48(0);
+#endif
 
     // generate random symmetric matrix
     for (uint i = 0 ; i < rows ; i++)
         for (uint j = i ; j < cols ; j++)
         {
             if (sparse_prob != 0.0)
+#ifdef WIN32
+            if (sparse_prob != 0.0)
+                if ( double( rand() ) / RAND_MAX < sparse_prob)
+                    continue;
+            T(i, j) = double( rand() ) / RAND_MAX;
+#else
+            if (sparse_prob != 0.0)
                 if (drand48() < sparse_prob)
                     continue;
             T(i, j) = drand48();
+#endif
             T(j, i) = T(i, j);
         }
     // use positive definite matrices
@@ -80,7 +92,11 @@ void TestLinearSolve::TestLinearSolveComputation()
     {
       NICE::Vector x ( rows );
       for ( uint j = 0 ; j < x.size(); j++ )
+#ifdef WIN32
+		x[j] = double( rand() ) / RAND_MAX;
+#else
         x[j] = drand48();
+#endif
       Vector yg;
       Vector ys;
       Tg.multiply ( yg, x );

+ 20 - 20
core/image/tests/TestMorph.cpp

@@ -28,7 +28,7 @@ void TestMorph::testRanking()
         for(int i=1; i<=3; ++i)
             srcall.setPixelQuick(i,j, i+3*(j-1) );
     for(int i=1; i<=9; ++i) {
-        result = rank(srcall, 1,i);
+        result = NICE::rank(srcall, 1,i);
         CPPUNIT_ASSERT_EQUAL(i, static_cast<int>(result->getPixel(2,2)));
     }
 
@@ -40,32 +40,32 @@ void TestMorph::testRanking()
             src(x,y) = x+y;
 
     // test exceptions
-    CPPUNIT_ASSERT_THROW(rank(src,1,0), ImageException);
-    CPPUNIT_ASSERT_THROW(rank(src,1,10), ImageException);
+    CPPUNIT_ASSERT_THROW(NICE::rank(src,1,0), ImageException);
+    CPPUNIT_ASSERT_THROW(NICE::rank(src,1,10), ImageException);
 
     // test ranking operation
         // rank = min
-        result = rank(src, 1,1);
+        result = NICE::rank(src, 1,1);
         for(int j=1; j<height-1; ++j)
             for(int i=1; i<width-1; ++i)
                 CPPUNIT_ASSERT_EQUAL((i-1)+(j-1), static_cast<int>(result->getPixel(i,j)));
         // rank = 2
-        result = rank(src, 1,2,result);
+        result = NICE::rank(src, 1,2,result);
         for(int j=1; j<height-1; ++j)
             for(int i=1; i<width-1; ++i)
                 CPPUNIT_ASSERT_EQUAL(i+j-1      , static_cast<int>(result->getPixel(i,j)));
         // rank = median
-        result = rank(src, 1,5,result);
+        result = NICE::rank(src, 1,5,result);
         for(int j=1; j<height-1; ++j)
             for(int i=1; i<width-1; ++i)
                 CPPUNIT_ASSERT_EQUAL(i+j        , static_cast<int>(result->getPixel(i,j)));
         // rank = 7
-        result = rank(src, 1,7,result);
+        result = NICE::rank(src, 1,7,result);
         for(int j=1; j<height-1; ++j)
             for(int i=1; i<width-1; ++i)
                 CPPUNIT_ASSERT_EQUAL(i+j+1      , static_cast<int>(result->getPixel(i,j)));
         // rank = max
-        result = rank(src, 1,9,result);
+        result = NICE::rank(src, 1,9,result);
         for(int j=1; j<height-1; ++j)
             for(int i=1; i<width-1; ++i)
                 CPPUNIT_ASSERT_EQUAL((i+1)+(j+1), static_cast<int>(result->getPixel(i,j)));
@@ -73,7 +73,7 @@ void TestMorph::testRanking()
     // test IP ranking operation with the help of the testet ranking operation
 
         // rank = min
-        result = rank(src, 1,1);
+        result = NICE::rank(src, 1,1);
         temp   = new Image(src);
         rankingIP(*temp, 1);
 
@@ -81,7 +81,7 @@ void TestMorph::testRanking()
             for(int x=1; x<width-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*result)(x,y)), static_cast<int>((*temp)(x,y)) );
         // rank = 2
-        result = rank(src, 1,2,result);
+        result = NICE::rank(src, 1,2,result);
         temp   = new Image(src);
         rankingIP(*temp, 2);
         for(int y=1; y<height-1; ++y)
@@ -89,7 +89,7 @@ void TestMorph::testRanking()
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*result)(x,y)), static_cast<int>((*temp)(x,y)) );
 
         // rank = median
-        result = rank(src, 1,5,result);
+        result = NICE::rank(src, 1,5,result);
         temp   = new Image(src);
         rankingIP(*temp, 5);
         for(int y=1; y<height-1; ++y)
@@ -97,7 +97,7 @@ void TestMorph::testRanking()
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*result)(x,y)), static_cast<int>((*temp)(x,y)) );
 
         // rank = 7
-        result = rank(src, 1,7,result);
+        result = NICE::rank(src, 1,7,result);
         temp   = new Image(src);
         rankingIP(*temp, 7);
         for(int y=1; y<height-1; ++y)
@@ -105,7 +105,7 @@ void TestMorph::testRanking()
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*result)(x,y)), static_cast<int>((*temp)(x,y)) );
 
         // rank = max
-        result = rank(src, 1,9,result);
+        result = NICE::rank(src, 1,9,result);
         temp   = new Image(src);
         rankingIP(*temp, 9);
         for(int y=1; y<height-1; ++y)
@@ -404,35 +404,35 @@ void TestMorph::testRankingWithStructure()
 
         // rank = 1
         rresult   = erode(src);
-        result    = rank(src, structure, 1);
+        result    = NICE::rank(src, structure, 1);
         for(int y=1; y<src.height()-1; ++y)
             for(int x=1; x<src.width()-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*rresult)(x,y)), static_cast<int>((*result)(x,y)) );
 
         // rank = 2
-        rresult   = rank(src, 1, 2, rresult);
-        result    = rank(src, structure, 2, result);
+        rresult   = NICE::rank(src, 1, 2, rresult);
+        result    = NICE::rank(src, structure, 2, result);
         for(int y=1; y<src.height()-1; ++y)
             for(int x=1; x<src.width()-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*rresult)(x,y)), static_cast<int>((*result)(x,y)) );
 
         // rank = median
         rresult   = median(src, rresult);
-        result    = rank(src, structure, 5, result);
+        result    = NICE::rank(src, structure, 5, result);
         for(int y=1; y<src.height()-1; ++y)
             for(int x=1; x<src.width()-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*rresult)(x,y)), static_cast<int>((*result)(x,y)) );
 
         // rank = 7
-        rresult   = rank(src, 1, 7, rresult);
-        result    = rank(src, structure, 7, result);
+        rresult   = NICE::rank(src, 1, 7, rresult);
+        result    = NICE::rank(src, structure, 7, result);
         for(int y=1; y<src.height()-1; ++y)
             for(int x=1; x<src.width()-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*rresult)(x,y)), static_cast<int>((*result)(x,y)) );
 
         // rank = 9
         rresult   = dilate(src, rresult);
-        result    = rank(src, structure, 9, result);
+        result    = NICE::rank(src, structure, 9, result);
         for(int y=1; y<src.height()-1; ++y)
             for(int x=1; x<src.width()-1; ++x)
                 CPPUNIT_ASSERT_EQUAL( static_cast<int>((*rresult)(x,y)), static_cast<int>((*result)(x,y)) );