]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Add test of a sphere
authorEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 07:46:00 +0000 (09:46 +0200)
committerEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 07:46:00 +0000 (09:46 +0200)
resources/CMakeLists.txt
resources/ShapeRecognSphere.med [new file with mode: 0755]
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/SphereTest.cxx [new file with mode: 0644]
src/ShapeRecogn/Test/SphereTest.hxx [new file with mode: 0644]
src/ShapeRecogn/Test/TestShapeRecogn.cxx

index 919b6486ebfa356c493a7f716ee36bac273920fb..9d5f66c985ebf18465d0b8bd0f0a5207598002cc 100644 (file)
@@ -97,6 +97,7 @@ SET(MED_other_FILES
   ShapeRecognPlane.med
   ShapeRecognCylinder.med
   ShapeRecognCone.med
+  ShapeRecognSphere.med
   )
 
 SET(MED_RESOURCES_FILES ${MED_test_fig_files})
diff --git a/resources/ShapeRecognSphere.med b/resources/ShapeRecognSphere.med
new file mode 100755 (executable)
index 0000000..4d7e700
Binary files /dev/null and b/resources/ShapeRecognSphere.med differ
index 713284d326b7b891cf523610e739b65f93e48fc2..e957ba522a4506f93f5a4831854b12120c428d89 100644 (file)
@@ -35,6 +35,7 @@ SET(TestShapeRecogn_SOURCES
   PlaneTest.cxx
   CylinderTest.cxx
   ConeTest.cxx
+  SphereTest.cxx
 )
 
 SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/resources")
diff --git a/src/ShapeRecogn/Test/SphereTest.cxx b/src/ShapeRecogn/Test/SphereTest.cxx
new file mode 100644 (file)
index 0000000..0cf1272
--- /dev/null
@@ -0,0 +1,36 @@
+#include "SphereTest.hxx"
+
+#include "ShapeRecognMesh.hxx"
+#include "Areas.hxx"
+#include "MathOps.hxx"
+#include "TestInterpKernelUtils.hxx" // getResourceFile()
+
+using namespace MEDCoupling;
+
+void SphereTest::setUp()
+{
+    std::string file = INTERP_TEST::getResourceFile("ShapeRecognSphere.med", 3);
+    srMesh = new ShapeRecognMesh(file);
+    srMesh->recognize();
+    areas = srMesh->getAreas();
+}
+
+void SphereTest::tearDown()
+{
+    if (srMesh != 0)
+        delete srMesh;
+    areas = 0;
+}
+
+void SphereTest::testArea()
+{
+    CPPUNIT_ASSERT_EQUAL(1, (int)areas->getNumberOfAreas());
+    // 8 double nodes so 147 - 6 nodes
+    CPPUNIT_ASSERT_EQUAL(141, (int)areas->getNumberOfNodes(0));
+    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Sphere, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, areas->getRadius(0), 1E-2);
+    std::array<double, 3> centerRef = {5.3, -6.7, -9.02};
+    std::array<double, 3> center = areas->getCenter(0);
+    for (size_t j = 0; j < 3; ++j)
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(centerRef[j], center[j], 1E-2);
+}
diff --git a/src/ShapeRecogn/Test/SphereTest.hxx b/src/ShapeRecogn/Test/SphereTest.hxx
new file mode 100644 (file)
index 0000000..abcfbfc
--- /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 __SPHERETEST_HXX__
+#define __SPHERETEST_HXX__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace MEDCoupling
+{
+    class ShapeRecognMesh;
+    class Areas;
+
+    class SphereTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE(SphereTest);
+        CPPUNIT_TEST(testArea);
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+        void setUp() override;
+        void tearDown() override;
+
+        void testArea();
+
+    private:
+        ShapeRecognMesh *srMesh = 0;
+        const Areas *areas;
+    };
+};
+
+#endif // __SPHERETEST_HXX__
index 134f35b4bfe30354a65f67346ca049ff9be3601a..6c09cba822e2002bfc5dc98b886283f5baddbbee 100644 (file)
 #include "PlaneTest.hxx"
 #include "CylinderTest.hxx"
 #include "ConeTest.hxx"
+#include "SphereTest.hxx"
 
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::MathOpsTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::PlaneTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::CylinderTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::ConeTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::SphereTest);
 
 #include "BasicMainTest.hxx"