]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Add tests
authorEl Hadi Moussi <moussi@phimeca.com>
Mon, 5 Aug 2024 17:04:30 +0000 (19:04 +0200)
committerEl Hadi Moussi <moussi@phimeca.com>
Mon, 5 Aug 2024 17:04:30 +0000 (19:04 +0200)
src/ShapeRecogn/CMakeLists.txt
src/ShapeRecogn/Test/CMakeLists.txt [new file with mode: 0644]
src/ShapeRecogn/Test/CTestTestfileInstall.cmake [new file with mode: 0644]
src/ShapeRecogn/Test/PlaneTest.cxx [new file with mode: 0644]
src/ShapeRecogn/Test/PlaneTest.hxx [new file with mode: 0644]
src/ShapeRecogn/Test/TestShapeRecogn.cxx [new file with mode: 0644]

index e1797d591954c5f2464035a5bf6408237c3785ed..a4dc5717e1d20567c98feee2904ad7ade69b2b85 100644 (file)
@@ -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 (file)
index 0000000..83a1926
--- /dev/null
@@ -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 (file)
index 0000000..ab32ede
--- /dev/null
@@ -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 (file)
index 0000000..ea09ed1
--- /dev/null
@@ -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<double, 3> normal = areas->getNormal(0);
+    std::array<double, 3> normalRef = {0.78152546, 0.31060627, -0.54105609};
+    std::array<double, 3> 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 (file)
index 0000000..b728d9c
--- /dev/null
@@ -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 <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+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 (file)
index 0000000..d474b3f
--- /dev/null
@@ -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"