From 83b5ca4cf0c18b52bebe4fae726184e1e232c90a Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 17 Jan 2012 08:27:42 +0000 Subject: [PATCH] DataArrayDouble::findCommonTuples method. --- .../Test/MEDCouplingBasicsTest4.cxx | 69 +++++++++++++++++++ .../Test/MEDCouplingBasicsTest4.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 47 +++++++++++++ 3 files changed, 118 insertions(+) diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 330b76129..5830f62e3 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1738,3 +1738,72 @@ void MEDCouplingBasicsTest4::testChangeUnderlyingMeshWithCMesh1() mesh2->decrRef(); mesh->decrRef(); } + +void MEDCouplingBasicsTest4::testDADFindCommonTuples1() +{ + DataArrayDouble *da=DataArrayDouble::New(); + da->alloc(6,1); + const double array1[6]={2.3,1.2,1.3,2.3,2.301,0.8}; + std::copy(array1,array1+6,da->getPointer()); + DataArrayInt *c=0,*cI=0; + // nbOftuples=1 + da->findCommonTuples(1e-2,-1,c,cI); + const int expected1[3]={0,3,4}; + const int expected2[2]={0,3}; + CPPUNIT_ASSERT_EQUAL(3,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(2,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // + da->findCommonTuples(2e-1,-1,c,cI); + const int expected3[5]={0,3,4,1,2}; + const int expected4[3]={0,3,5}; + CPPUNIT_ASSERT_EQUAL(5,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // nbOftuples=2 + da->alloc(6,2); + const double array2[12]={2.3,2.3,1.2,1.2,1.3,1.3,2.3,2.3,2.301,2.301,0.8,0.8}; + std::copy(array2,array2+12,da->getPointer()); + da->findCommonTuples(1e-2,-1,c,cI); + CPPUNIT_ASSERT_EQUAL(3,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(2,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // + da->findCommonTuples(2e-1,-1,c,cI); + CPPUNIT_ASSERT_EQUAL(5,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // nbOftuples=3 + da->alloc(6,3); + const double array3[18]={2.3,2.3,2.3,1.2,1.2,1.2,1.3,1.3,1.3,2.3,2.3,2.3,2.301,2.301,2.301,0.8,0.8,0.8}; + std::copy(array3,array3+18,da->getPointer()); + da->findCommonTuples(1e-2,-1,c,cI); + CPPUNIT_ASSERT_EQUAL(3,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(2,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected1,expected1+3,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+2,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // + da->findCommonTuples(2e-1,-1,c,cI); + CPPUNIT_ASSERT_EQUAL(5,c->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(3,cI->getNbOfElems()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+5,c->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+3,cI->getConstPointer())); + c->decrRef(); + cI->decrRef(); + // + da->decrRef(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx index cefcc4046..4e4d2ee9c 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx @@ -81,6 +81,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testDaDSetPartOfValuesAdv1 ); CPPUNIT_TEST( testUMeshBuildSetInstanceFromThis1 ); CPPUNIT_TEST( testUMeshMergeMeshesCVW1 ); + CPPUNIT_TEST( testDADFindCommonTuples1 ); CPPUNIT_TEST_SUITE_END(); public: void testDescriptionInMeshTimeUnit1(); @@ -131,6 +132,7 @@ namespace ParaMEDMEM void testUMeshBuildSetInstanceFromThis1(); void testUMeshMergeMeshesCVW1(); void testChangeUnderlyingMeshWithCMesh1(); + void testDADFindCommonTuples1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index c64947c0e..1fd2f66df 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7911,6 +7911,53 @@ class MEDCouplingBasicsTest(unittest.TestCase): f.changeUnderlyingMesh(mesh2,myId,1e-12); pass pass + + def testDADFindCommonTuples1(self): + da=DataArrayDouble.New(); + # nbOftuples=1 + array1=[2.3,1.2,1.3,2.3,2.301,0.8] + da.setValues(array1,6,1) + c,cI=da.findCommonTuples(1e-2); + expected1=[0,3,4] + expected2=[0,3] + self.assertEqual(3,c.getNbOfElems()); + self.assertEqual(2,cI.getNbOfElems()); + self.assertEqual(expected1,c.getValues()) + self.assertEqual(expected2,cI.getValues()) + c,cI=da.findCommonTuples(2e-1) + expected3=[0,3,4,1,2] + expected4=[0,3,5] + self.assertEqual(5,c.getNbOfElems()); + self.assertEqual(3,cI.getNbOfElems()); + self.assertEqual(expected3,c.getValues()) + self.assertEqual(expected4,cI.getValues()) + # nbOftuples=2 + array2=[2.3,2.3,1.2,1.2,1.3,1.3,2.3,2.3,2.301,2.301,0.8,0.8] + da.setValues(array2,6,2) + c,cI=da.findCommonTuples(1e-2); + self.assertEqual(3,c.getNbOfElems()); + self.assertEqual(2,cI.getNbOfElems()); + self.assertEqual(expected1,c.getValues()) + self.assertEqual(expected2,cI.getValues()) + c,cI=da.findCommonTuples(2e-1) + self.assertEqual(5,c.getNbOfElems()); + self.assertEqual(3,cI.getNbOfElems()); + self.assertEqual(expected3,c.getValues()) + self.assertEqual(expected4,cI.getValues()) + # nbOftuples=3 + array3=[2.3,2.3,2.3,1.2,1.2,1.2,1.3,1.3,1.3,2.3,2.3,2.3,2.301,2.301,2.301,0.8,0.8,0.8] + da.setValues(array3,6,3) + c,cI=da.findCommonTuples(1e-2); + self.assertEqual(3,c.getNbOfElems()); + self.assertEqual(2,cI.getNbOfElems()); + self.assertEqual(expected1,c.getValues()) + self.assertEqual(expected2,cI.getValues()) + c,cI=da.findCommonTuples(2e-1) + self.assertEqual(5,c.getNbOfElems()); + self.assertEqual(3,cI.getNbOfElems()); + self.assertEqual(expected3,c.getValues()) + self.assertEqual(expected4,cI.getValues()) + pass def setUp(self): pass -- 2.39.2