From 2b62a936d78588e473ccdeb1414115f777396c57 Mon Sep 17 00:00:00 2001 From: El Hadi Moussi Date: Mon, 5 Aug 2024 19:04:30 +0200 Subject: [PATCH] Add tests --- src/ShapeRecogn/CMakeLists.txt | 10 ++-- src/ShapeRecogn/Test/CMakeLists.txt | 60 +++++++++++++++++++ .../Test/CTestTestfileInstall.cmake | 31 ++++++++++ src/ShapeRecogn/Test/PlaneTest.cxx | 42 +++++++++++++ src/ShapeRecogn/Test/PlaneTest.hxx | 49 +++++++++++++++ src/ShapeRecogn/Test/TestShapeRecogn.cxx | 24 ++++++++ 6 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 src/ShapeRecogn/Test/CMakeLists.txt create mode 100644 src/ShapeRecogn/Test/CTestTestfileInstall.cmake create mode 100644 src/ShapeRecogn/Test/PlaneTest.cxx create mode 100644 src/ShapeRecogn/Test/PlaneTest.hxx create mode 100644 src/ShapeRecogn/Test/TestShapeRecogn.cxx diff --git a/src/ShapeRecogn/CMakeLists.txt b/src/ShapeRecogn/CMakeLists.txt index e1797d591..a4dc5717e 100644 --- a/src/ShapeRecogn/CMakeLists.txt +++ b/src/ShapeRecogn/CMakeLists.txt @@ -27,16 +27,16 @@ IF(MEDCOUPLING_ENABLE_PYTHON) ADD_SUBDIRECTORY(Swig) ENDIF(MEDCOUPLING_ENABLE_PYTHON) -# IF(MEDCOUPLING_BUILD_TESTS) -# ADD_SUBDIRECTORY(Test) -# ENDIF(MEDCOUPLING_BUILD_TESTS) +IF(MEDCOUPLING_BUILD_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF(MEDCOUPLING_BUILD_TESTS) INCLUDE_DIRECTORIES( ${MEDFILE_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS} ${LAPACKE_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases ) @@ -52,7 +52,7 @@ SET(shaperecogn_SOURCES ADD_LIBRARY(shaperecogn ${shaperecogn_SOURCES}) SET_TARGET_PROPERTIES(shaperecogn PROPERTIES COMPILE_FLAGS "") -TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${LAPACK_LIBRARIES}) +TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${LAPACK_LIBRARIES}) INSTALL(TARGETS shaperecogn EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${MEDCOUPLING_INSTALL_LIBS}) FILE(GLOB shaperecogn_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") diff --git a/src/ShapeRecogn/Test/CMakeLists.txt b/src/ShapeRecogn/Test/CMakeLists.txt new file mode 100644 index 000000000..83a192666 --- /dev/null +++ b/src/ShapeRecogn/Test/CMakeLists.txt @@ -0,0 +1,60 @@ +# Copyright (C) 2012-2024 CEA, EDF +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE_DIRECTORIES( + ${CPPUNIT_INCLUDE_DIRS} + ${HDF5_INCLUDE_DIRS} + ${MEDFILE_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_SOURCE_DIR}/../../MEDLoader + ${CMAKE_CURRENT_SOURCE_DIR}/../../MEDCoupling + ${CMAKE_CURRENT_SOURCE_DIR}/../../INTERP_KERNEL + ${CMAKE_CURRENT_SOURCE_DIR}/../../INTERP_KERNEL/Bases + ${CMAKE_CURRENT_SOURCE_DIR}/../../INTERP_KERNELTest # For common CppUnitTest.hxx file and TestIKUtils.hxx + ) + +SET(TestShapeRecogn_SOURCES + TestShapeRecogn.cxx + PlaneTest.cxx +) + +SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/resources") +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +ADD_EXECUTABLE(TestShapeRecogn ${TestShapeRecogn_SOURCES}) +TARGET_LINK_LIBRARIES(TestShapeRecogn shaperecogn InterpKernelTestUtils ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS}) + +INSTALL(TARGETS TestShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_BINS}) + +SET(BASE_TESTS TestShapeRecogn) + +# FOREACH(test ${BASE_TESTS}) +# ADD_TEST(NAME ${test} +# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MCTestLauncher.py ${CMAKE_CURRENT_BINARY_DIR}/${test}) +# SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}") +# ENDFOREACH() + +# # Application tests + +# SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn) +# INSTALL(TARGETS TestShapeRecogn DESTINATION ${TEST_INSTALL_DIRECTORY}) + +# INSTALL(FILES CTestTestfileInstall.cmake +# DESTINATION ${TEST_INSTALL_DIRECTORY} +# RENAME CTestTestfile.cmake) diff --git a/src/ShapeRecogn/Test/CTestTestfileInstall.cmake b/src/ShapeRecogn/Test/CTestTestfileInstall.cmake new file mode 100644 index 000000000..ab32ede46 --- /dev/null +++ b/src/ShapeRecogn/Test/CTestTestfileInstall.cmake @@ -0,0 +1,31 @@ +# Copyright (C) 2015-2024 CEA, EDF +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(TEST_NAMES + TestShapeRecogn +) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python3 MCTestLauncher.py ${tfile}) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + TIMEOUT ${TIMEOUT} + ) +ENDFOREACH() diff --git a/src/ShapeRecogn/Test/PlaneTest.cxx b/src/ShapeRecogn/Test/PlaneTest.cxx new file mode 100644 index 000000000..ea09ed1ce --- /dev/null +++ b/src/ShapeRecogn/Test/PlaneTest.cxx @@ -0,0 +1,42 @@ +#include "PlaneTest.hxx" + +#include "ShapeRecognMesh.hxx" +#include "Areas.hxx" +#include "MathOps.hxx" + +using namespace MEDCoupling; + +void PlaneTest::setUp() +{ + srMesh = new ShapeRecognMesh("shaperecogn_examples/plane.med"); + srMesh->recognize(); + areas = srMesh->getAreas(); +} + +void PlaneTest::tearDown() +{ + if (srMesh != 0) + delete srMesh; + areas = 0; +} + +void PlaneTest::testArea() +{ + CPPUNIT_ASSERT_EQUAL(46, (int)areas->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(1, (int)areas->getNumberOfAreas()); + // Normal + std::array normal = areas->getNormal(0); + std::array normalRef = {0.78152546, 0.31060627, -0.54105609}; + std::array affinePoint = areas->getAffinePoint(0); + double proportion0 = normal[0] / normalRef[0]; + double proportion1 = normal[1] / normalRef[1]; + double proportion2 = normal[2] / normalRef[2]; + double proportion3 = MathOps::dot(normal, affinePoint) / MathOps::dot(normalRef, affinePoint); + // Check proportions between the normal vectors of the two planes + CPPUNIT_ASSERT_DOUBLES_EQUAL(proportion0, proportion1, 1E-2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(proportion0, proportion2, 1E-2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(proportion0, proportion3, 1E-1); + // Check the angle + double angle = MathOps::computeAngle(normal, normalRef); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, angle, 1E-2); +} diff --git a/src/ShapeRecogn/Test/PlaneTest.hxx b/src/ShapeRecogn/Test/PlaneTest.hxx new file mode 100644 index 000000000..b728d9c31 --- /dev/null +++ b/src/ShapeRecogn/Test/PlaneTest.hxx @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __PLANETEST_HXX__ +#define __PLANETEST_HXX__ + +#include +#include + +namespace MEDCoupling +{ + class ShapeRecognMesh; + class Areas; + + class PlaneTest : public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE(PlaneTest); + CPPUNIT_TEST(testArea); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() override; + void tearDown() override; + + void testArea(); + + private: + ShapeRecognMesh *srMesh = 0; + const Areas *areas; + }; +}; + +#endif // __PLANETEST_HXX__ diff --git a/src/ShapeRecogn/Test/TestShapeRecogn.cxx b/src/ShapeRecogn/Test/TestShapeRecogn.cxx new file mode 100644 index 000000000..d474b3f1c --- /dev/null +++ b/src/ShapeRecogn/Test/TestShapeRecogn.cxx @@ -0,0 +1,24 @@ +// Copyright (C) 2007-2024 CEA, EDF +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "PlaneTest.hxx" + +CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::PlaneTest); + +#include "BasicMainTest.hxx" -- 2.39.2