Salome HOME
implementation of the strickler types (integer codes) for points
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Bathymetry.cxx
index e3b2509a4ec903299251ce162cf76151133e039e..1c0fc6edaef330264ede9456b75f64278ca925f3 100644 (file)
 
 #include <gp_Pnt2d.hxx>
 
+const double EPS = 1E-4;
+
 void generateOne( QTextStream& theStream,
                   double theFirstX, double theFirstY,
                   double theLastX, double theLastY )
 {
   const int aNbPoints = 50;
-
-  double aComDist = gp_Pnt2d( theFirstX, theFirstY ).Distance( gp_Pnt2d( theLastX, theLastY ) );
-  double aStep = aComDist / (double)aNbPoints;
-
   double aStepZ = -5;
-  double aCurDist = 0.0;
-  for ( int i = 0; i <= aNbPoints; ++i )
+  const double dt = 1.0 / aNbPoints;
+  
+  for( double t=0.0; t<=1.0; t += dt )
   {
-    double aRatio = ( aCurDist / ( aComDist - aCurDist ) );
-
-    double anX = ( theFirstX + aRatio * theLastX ) / ( 1 + aRatio );
-    double anY = ( theFirstY + aRatio * theLastY ) / ( 1 + aRatio );
-    double aZ = aStepZ * aStepZ + sin( (float)rand() );
+    double anX = theFirstX * (1-t) + theLastX * t;
+    double anY = theFirstY * (1-t) + theLastY * t;
+    double aZ = aStepZ * aStepZ + sin( 10*t );
     theStream << anX << " " << anY << " " << aZ << " \n";
 
-    aCurDist += aStep;
     aStepZ += 0.2;
   }
 }
@@ -65,7 +61,6 @@ bool test_HYDROData_Bathymetry::createTestFile( const QString& theFileName )
   {
     QTextStream anOutStream( &aTmpFile );
 
-    srand( 4587 );
     generateOne( anOutStream, 0, 5, 0, -5 );
     generateOne( anOutStream, 10, 5, 10, -5 );
     generateOne( anOutStream, 20, 5, 20, -5 );
@@ -130,34 +125,34 @@ void test_HYDROData_Bathymetry::testFileImport()
   if ( !createTestFile( aFileName ) )
     return; // No file has been created
 
-  CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName.toStdString().c_str() ) );
+  CPPUNIT_ASSERT( aBathymetry->ImportFromFiles( QStringList(aFileName)) );
 
   HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints();
-  CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+  CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
 
   gp_XY aTestPoint( 1, 1 );
-  double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
+  double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.2432, anAltitude, EPS );
 
   aTestPoint = gp_XY( 0.5, 0.5 );
-  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.591602, anAltitude, EPS );
 
   aTestPoint = gp_XY( 1.5, 1 );
-  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.2432, anAltitude, EPS );
 
   aTestPoint = gp_XY( 1.5, 0.7 );
-  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.591602, anAltitude, EPS );
 
   aTestPoint = gp_XY( 1.5, -0.7 );
-  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.271267, anAltitude, EPS );
 
   aTestPoint = gp_XY( 2, 3.5 );
-  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
-  CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) );
+  anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.9454, anAltitude, EPS );
 
   aDoc->Close();
 }
@@ -176,10 +171,10 @@ void test_HYDROData_Bathymetry::testCopy()
   
   if ( anIsFileCreated )
   {
-    CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName.toStdString().c_str() ) );
+    CPPUNIT_ASSERT( aBathymetry1->ImportFromFiles( QStringList(aFileName ) ) );
 
     HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints();
-    CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+    CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
   }
 
   Handle(HYDROData_Bathymetry) aBathymetry2 = 
@@ -190,7 +185,7 @@ void test_HYDROData_Bathymetry::testCopy()
   if ( anIsFileCreated )
   {
     HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints();
-    CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+    CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
   }
 
   aDoc->Close();