Skip to content

Commit

Permalink
[tests] Use appropriate gtest macro (sofa-framework#4607)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored Mar 22, 2024
1 parent d78242c commit 6436aae
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions Sofa/Component/Engine/Generate/tests/MergePoints_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ struct MergePoints_test : public BaseSimulationTest,
ASSERT_EQ(points.size(),4);
ASSERT_EQ(indices1.size(),2);
ASSERT_EQ(indices2.size(),2);
ASSERT_TRUE( (Coord(0.0f, 0.0f, 0.0f)-points[0]).norm() < 0.000000001f);
ASSERT_TRUE( (Coord(1.0f, 0.0f, 0.0f)-points[1]).norm() < 0.000000001f);
ASSERT_TRUE( (Coord(0.0f, 1.0f, 0.0f)-points[2]).norm() < 0.000000001f);
ASSERT_TRUE( (Coord(0.0f, 0.0f, 1.0f)-points[3]).norm() < 0.000000001f);
ASSERT_LT( (Coord(0.0f, 0.0f, 0.0f)-points[0]).norm(), 0.000000001f);
ASSERT_LT( (Coord(1.0f, 0.0f, 0.0f)-points[1]).norm(), 0.000000001f);
ASSERT_LT( (Coord(0.0f, 1.0f, 0.0f)-points[2]).norm(), 0.000000001f);
ASSERT_LT( (Coord(0.0f, 0.0f, 1.0f)-points[3]).norm(), 0.000000001f);
ASSERT_EQ(indices1[0],0);
ASSERT_EQ(indices1[1],1);
ASSERT_EQ(indices2[0],2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void RestStiffSpringsForceField_test::checkDifference(MechanicalObject<Type>& mo
}
else
{
ASSERT_TRUE( fabs(pos.x()-rpos.x()) < 1 );
ASSERT_TRUE( fabs(pos.y()-rpos.y()) < 1 );
ASSERT_TRUE( fabs(pos.z()-rpos.z()) < 1 );
ASSERT_LT( fabs(pos.x()-rpos.x()), 1 );
ASSERT_LT( fabs(pos.y()-rpos.y()), 1 );
ASSERT_LT( fabs(pos.z()-rpos.z()), 1 );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ struct StiffSpringForceField_test : public ForceField_test<_StiffSpringForceFiel
std::cout << " expected fc = " << fc << std::endl;
std::cout << " actual fc = " << actualfc.ref() << std::endl;
}
ASSERT_TRUE( this->vectorMaxDiff(fp,actualfp)< this->errorMax*this->epsilon() );
ASSERT_TRUE( this->vectorMaxDiff(fc,actualfc)< this->errorMax*this->epsilon() );
ASSERT_LT( this->vectorMaxDiff(fp,actualfp), this->errorMax*this->epsilon() );
ASSERT_LT( this->vectorMaxDiff(fc,actualfc), this->errorMax*this->epsilon() );
}

///@}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ struct ForceField_test : public BaseSimulationTest, NumericTest<typename _ForceF
if( deltaRange.second / errorMax <= sofa::testing::g_minDeltaErrorRatio )
ADD_FAILURE() << "The comparison threshold is too large for the finite difference delta";

ASSERT_TRUE(x.size()==v.size());
ASSERT_TRUE(x.size()==ef.size());
ASSERT_EQ(x.size(), v.size());
ASSERT_EQ(x.size(), ef.size());
std::size_t n = x.size();

// copy the position and velocities to the scene graph
Expand Down Expand Up @@ -195,7 +195,7 @@ struct ForceField_test : public BaseSimulationTest, NumericTest<typename _ForceF
std::cout << " expected f = " << ef << std::endl;
std::cout << " actual f = " << f.ref() << std::endl;
}
ASSERT_TRUE( this->vectorMaxDiff(f,ef)< errorMax*this->epsilon() );
ASSERT_LT( this->vectorMaxDiff(f,ef), errorMax*this->epsilon() );

if( !checkStiffness ) return;

Expand Down
8 changes: 4 additions & 4 deletions Sofa/framework/Core/test/DataEngine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ struct DataEngine_test: public BaseTest
void testTrackedData(T& engine)
{
// input did not change, it is not dirtied, so neither its associated DataTracker
ASSERT_TRUE(engine.output.getValue()==TestEngine::NO_CHANGED);
ASSERT_EQ(engine.output.getValue(), TestEngine::NO_CHANGED);

// modifying input sets it as dirty, so its associated DataTracker too
engine.input.setValue(true);
ASSERT_TRUE(engine.output.getValue()==TestEngine::CHANGED);
ASSERT_EQ(engine.output.getValue(), TestEngine::CHANGED);

// nothing changes, no one is dirty
engine.update();
ASSERT_TRUE(engine.output.getValue()==TestEngine::NO_CHANGED);
ASSERT_EQ(engine.output.getValue(), TestEngine::NO_CHANGED);

// modifying input sets it as dirty, so its associated DataTracker too
engine.input.setValue(true);
// cleaning/accessing the input will not clean its associated DataTracker
engine.input.cleanDirty();
ASSERT_TRUE(engine.output.getValue()==TestEngine::CHANGED);
ASSERT_EQ(engine.output.getValue(), TestEngine::CHANGED);
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CircularQueue_SingleProdSingleConsTest : public ::testing::Test
{
while(!queue.pop(value))
std::this_thread::yield();
EXPECT_TRUE(lastValue < value);
EXPECT_LT(lastValue, value);
lastValue = value;
}
}
Expand Down
54 changes: 27 additions & 27 deletions Sofa/framework/LinearAlgebra/test/Matrix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ struct TestSparseMatrices : public NumericTest<typename T::Real>
}
mb.compress();

ASSERT_TRUE( Inherit::matrixMaxDiff(ma,mb) < 100*Inherit::epsilon() );
ASSERT_LT( Inherit::matrixMaxDiff(ma,mb), 100*Inherit::epsilon() );

// building with ordered blocks

Expand All @@ -343,7 +343,7 @@ struct TestSparseMatrices : public NumericTest<typename T::Real>
}
mb.compress();

ASSERT_TRUE( Inherit::matrixMaxDiff(ma,mb) < 100*Inherit::epsilon() );
ASSERT_LT( Inherit::matrixMaxDiff(ma,mb), 100*Inherit::epsilon() );



Expand Down Expand Up @@ -371,7 +371,7 @@ struct TestSparseMatrices : public NumericTest<typename T::Real>
}
mb.compress();

ASSERT_TRUE( Inherit::matrixMaxDiff(ma,mb) < 100*Inherit::epsilon() );
ASSERT_LT( Inherit::matrixMaxDiff(ma,mb), 100*Inherit::epsilon() );



Expand Down Expand Up @@ -402,7 +402,7 @@ struct TestSparseMatrices : public NumericTest<typename T::Real>
}
mb.compress();

ASSERT_TRUE( Inherit::matrixMaxDiff(ma,mb) < 100*Inherit::epsilon() );
ASSERT_LT( Inherit::matrixMaxDiff(ma,mb), 100*Inherit::epsilon() );
}

bool checkEigenMatrixBlockFromCompressedRowSparseMatrix()
Expand Down Expand Up @@ -437,14 +437,14 @@ TYPED_TEST_SUITE(TestSparseMatrices, TestSparseMatricesImplementations);

// ==============================
// Set/get value tests
TYPED_TEST(TestSparseMatrices, set_fullMat ) { ASSERT_TRUE( this->matrixMaxDiff(this->mat,this->fullMat) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs_scalar ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->crsScalar ) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs1 ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->crs1) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs2 ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->crs2) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_mapMat ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->mapMat) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBlock1 ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->eiBlock1) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBlock2 ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->eiBlock2) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBase ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMat,this->eiBase) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_fullMat ) { ASSERT_LT( this->matrixMaxDiff(this->mat,this->fullMat), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs_scalar ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->crsScalar ), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs1 ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->crs1), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_crs2 ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->crs2), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_mapMat ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->mapMat), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBlock1 ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->eiBlock1), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBlock2 ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->eiBlock2), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, set_eiBase ) { ASSERT_LT( this->matrixMaxDiff(this->fullMat,this->eiBase), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, eigenMatrix_update ) { ASSERT_TRUE( this->checkEigenMatrixUpdate() ); }
TYPED_TEST(TestSparseMatrices, eigenMatrix_block_row_filling ) { this->checkEigenMatrixBlockRowFilling(); }
TYPED_TEST(TestSparseMatrices, eigenMatrixBlockFromCompressedRowSparseMatrix ) { ASSERT_TRUE( this->checkEigenMatrixBlockFromCompressedRowSparseMatrix() ); }
Expand All @@ -454,59 +454,59 @@ TYPED_TEST(TestSparseMatrices, eigenMapToDenseMatrix ) { ASSERT_TRUE( this->chec
// Matrix-Vector product tests
TYPED_TEST(TestSparseMatrices, set_fullVec_nrows_reference )
{
ASSERT_TRUE(this->vectorMaxDiff(this->vecM,this->fullVec_nrows_reference) < this->epsilon() );
ASSERT_LT(this->vectorMaxDiff(this->vecM,this->fullVec_nrows_reference), this->epsilon() );
}
TYPED_TEST(TestSparseMatrices, fullMat_vector_product )
{
// fullMat.opMulV(&fullVec_nrows_result,&fullVec_ncols);
this->fullVec_nrows_result = this->fullMat * this->fullVec_ncols;
ASSERT_TRUE(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result) < this->epsilon() );
ASSERT_LT(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result), this->epsilon() );
}
TYPED_TEST(TestSparseMatrices, mapMat_vector_product )
{
// mapMat.opMulV(&fullVec_nrows_result,&fullVec_ncols);
this->fullVec_nrows_result = this->mapMat * this->fullVec_ncols;
ASSERT_TRUE(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result) < this->epsilon() );
ASSERT_LT(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result), this->epsilon() );
}
TYPED_TEST(TestSparseMatrices, eiBlock1_vector_product )
{
// eiBlock1.opMulV(&fullVec_nrows_result,&fullVec_ncols);
// eiBlock1.multVector(fullVec_nrows_result,fullVec_ncols);
this->fullVec_nrows_result = this->eiBlock1 * this->fullVec_ncols;
ASSERT_TRUE(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result) < this->epsilon() );
ASSERT_LT(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result), this->epsilon() );

}
TYPED_TEST(TestSparseMatrices, crs1_vector_product )
{
// EXPECT_TRUE(NROWS%BROWS==0 && NCOLS%BCOLS==0) << "Error: CompressedRowSparseMatrix * Vector crashes when the size of the matrix is not a multiple of the size of the matrix blocks. Aborting this test, and reporting a failure."; // otherwise the product crashes
// crs1.opMulV(&fullVec_nrows_result,&fullVec_ncols);
this->fullVec_nrows_result = this->crs1 * this->fullVec_ncols;
ASSERT_TRUE(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result) < this->epsilon() );
ASSERT_LT(this->vectorMaxDiff(this->fullVec_nrows_reference,this->fullVec_nrows_result), this->epsilon() );
}


// ==============================
// Matrix product tests
TYPED_TEST(TestSparseMatrices, full_matrix_product ) { ASSERT_TRUE( this->matrixMaxDiff(this->matMultiplication,this->fullMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_scalar_matrix_product ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMultiplication,this->crsScalarMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_matrix_product ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMultiplication,this->crsMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, EigenBase_matrix_product ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullMultiplication,this->eiBaseMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, full_matrix_product ) { ASSERT_LT( this->matrixMaxDiff(this->matMultiplication,this->fullMultiplication), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_scalar_matrix_product ) { ASSERT_LT( this->matrixMaxDiff(this->fullMultiplication,this->crsScalarMultiplication), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_matrix_product ) { ASSERT_LT( this->matrixMaxDiff(this->fullMultiplication,this->crsMultiplication), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, EigenBase_matrix_product ) { ASSERT_LT( this->matrixMaxDiff(this->fullMultiplication,this->eiBaseMultiplication), 100*this->epsilon() ); }
//TYPED_TEST(TestSparseMatrices, EigenSparseDense_matrix_product ) { ASSERT_TRUE( EigenDenseMatrix(this->eiBaseMultiplication.compressedMatrix) == this->eiDenseMultiplication ); }
TYPED_TEST(TestSparseMatrices, full_matrix_transposeproduct ) { ASSERT_TRUE( this->matrixMaxDiff(this->matTransposeMultiplication,this->fullTransposeMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_scalar_matrix_transposeproduct ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullTransposeMultiplication,this->crsScalarTransposeMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_matrix_transposeproduct ) { ASSERT_TRUE( this->matrixMaxDiff(this->fullTransposeMultiplication,this->crsTransposeMultiplication) < 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, full_matrix_transposeproduct ) { ASSERT_LT( this->matrixMaxDiff(this->matTransposeMultiplication,this->fullTransposeMultiplication), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_scalar_matrix_transposeproduct ) { ASSERT_LT( this->matrixMaxDiff(this->fullTransposeMultiplication,this->crsScalarTransposeMultiplication), 100*this->epsilon() ); }
TYPED_TEST(TestSparseMatrices, crs_matrix_transposeproduct ) { ASSERT_LT( this->matrixMaxDiff(this->fullTransposeMultiplication,this->crsTransposeMultiplication), 100*this->epsilon() ); }

// Matrix addition
TYPED_TEST(TestSparseMatrices, crs_matrix_addition )
{
this->crs2 = this->crs1 + this->crs1;
ASSERT_TRUE( this->matrixMaxDiff(this->mat*2,this->crs2) < 100*this->epsilon() );
ASSERT_LT( this->matrixMaxDiff(this->mat*2,this->crs2), 100*this->epsilon() );

this->crs2 += this->crs1;
ASSERT_TRUE( this->matrixMaxDiff(this->mat*3,this->crs2) < 100*this->epsilon() );
ASSERT_LT( this->matrixMaxDiff(this->mat*3,this->crs2), 100*this->epsilon() );

this->crs2 -= this->crs1;
ASSERT_TRUE( this->matrixMaxDiff(this->mat*2,this->crs2) < 100*this->epsilon() );
ASSERT_LT( this->matrixMaxDiff(this->mat*2,this->crs2), 100*this->epsilon() );
}

#if BENCHMARK_MATRIX_PRODUCT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct TestSparseMatrixTranspose : public sofa::testing::SparseMatrixTest<typena
{
for(typename Transpose::InnerIterator it(transposeMatrix, i); it; ++it )
{
ASSERT_TRUE(it.row() < nbRows) << it.row() << " " << nbRows;
ASSERT_TRUE(it.col() < nbCols) << it.col() << " " << nbCols;
ASSERT_LT(it.row(), nbRows) << it.row() << " " << nbRows;
ASSERT_LT(it.col(), nbCols) << it.col() << " " << nbCols;
const Real initialValue = matrix.coeff(it.row(), it.col());

triplets.emplace_back(it.row(), it.col(), it.value());
Expand Down Expand Up @@ -119,4 +119,4 @@ TYPED_TEST(TestSparseMatrixTranspose, rectangularMatrix )
this->checkMatrix( 1000, 3000, 20. / 1000. );

this->checkMatrix( 100, 300, 1. );
}
}
4 changes: 2 additions & 2 deletions Sofa/framework/Type/test/Quater_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ TEST(QuaterTest, EulerAngles)
// make sure the angles don't lead to a singularity
for (const auto& angle : eulerAngles)
{
ASSERT_TRUE(std::abs(angle - M_PI / 2) >= 1e-3);
ASSERT_TRUE(std::abs(angle + M_PI / 2) >= 1e-3);
ASSERT_GE(std::abs(angle - M_PI / 2), 1e-3);
ASSERT_GE(std::abs(angle + M_PI / 2), 1e-3);
}

// Transform Euler angles back to a quaternion (q1)
Expand Down

0 comments on commit 6436aae

Please sign in to comment.