From: El Hadi Moussi Date: Wed, 7 Aug 2024 07:46:00 +0000 (+0200) Subject: Add test of a sphere X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d59f5128b42be8891328b48e35980af05fe326fd;p=tools%2Fmedcoupling.git Add test of a sphere --- diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 919b6486e..9d5f66c98 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -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 index 000000000..4d7e7008f Binary files /dev/null and b/resources/ShapeRecognSphere.med differ diff --git a/src/ShapeRecogn/Test/CMakeLists.txt b/src/ShapeRecogn/Test/CMakeLists.txt index 713284d32..e957ba522 100644 --- a/src/ShapeRecogn/Test/CMakeLists.txt +++ b/src/ShapeRecogn/Test/CMakeLists.txt @@ -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 index 000000000..0cf12728f --- /dev/null +++ b/src/ShapeRecogn/Test/SphereTest.cxx @@ -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 centerRef = {5.3, -6.7, -9.02}; + std::array 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 index 000000000..abcfbfc8a --- /dev/null +++ b/src/ShapeRecogn/Test/SphereTest.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 __SPHERETEST_HXX__ +#define __SPHERETEST_HXX__ + +#include +#include + +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__ diff --git a/src/ShapeRecogn/Test/TestShapeRecogn.cxx b/src/ShapeRecogn/Test/TestShapeRecogn.cxx index 134f35b4b..6c09cba82 100644 --- a/src/ShapeRecogn/Test/TestShapeRecogn.cxx +++ b/src/ShapeRecogn/Test/TestShapeRecogn.cxx @@ -21,10 +21,12 @@ #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"