]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
DataArrayDouble::findCommonTuples method.
authorageay <ageay>
Tue, 17 Jan 2012 08:27:42 +0000 (08:27 +0000)
committerageay <ageay>
Tue, 17 Jan 2012 08:27:42 +0000 (08:27 +0000)
src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 330b7612952dc0a193cc642f10d497290aba238a..5830f62e38f31aee2ea8c73acb5f6ff87f40f5ab 100644 (file)
@@ -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();
+}
index cefcc4046b1aa5cc9e7180c4686404e38e0b8d6e..4e4d2ee9c482eb631cbbb69a1848f3288755ec4f 100644 (file)
@@ -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();
   };
 }
 
index c64947c0e6086e41e0ed47ea8c2b5a2980904d88..1fd2f66df90b0c39495bee24d32ab51f9564049d 100644 (file)
@@ -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