]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug correction on computeOffsets2 for empty arrayint. Shame on me \!
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 16 Dec 2015 18:37:10 +0000 (19:37 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 16 Dec 2015 18:37:10 +0000 (19:37 +0100)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 998ac654e7c4e5797cf134765d6f0ae29cd9d48c..72d3a1fe320005f0c08468ccd84a2e823f83cb0a 100644 (file)
@@ -10356,8 +10356,6 @@ void DataArrayInt::computeOffsets2()
     throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
   int nbOfTuples=getNumberOfTuples();
   int *ret=(int *)malloc((nbOfTuples+1)*sizeof(int));
-  if(nbOfTuples==0)
-    return ;
   const int *work=getConstPointer();
   ret[0]=0;
   for(int i=0;i<nbOfTuples;i++)
index 18118dc7534bb852563033fb71251591ff905882..8e19f49e6a38dc9d4fe5d9de1247e428f6489bea 100644 (file)
@@ -16770,6 +16770,19 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertTrue(not "mismatch" in m.__repr__())# bug was here !
         pass
 
+    def testSwig2BugComputeOffsets1(self):
+        """Non regression test. computeOffsets2 on empty array must return 0."""
+        d=DataArrayInt([3])
+        d.computeOffsets2()
+        self.assertTrue(d.isEqual(DataArrayInt([0,3])))
+        d=DataArrayInt([])
+        d.computeOffsets()
+        self.assertTrue(d.isEqual(DataArrayInt([])))
+        d=DataArrayInt([])
+        d.computeOffsets2()
+        self.assertTrue(d.isEqual(DataArrayInt([0]))) # <- bug was here
+        pass
+
     pass
 
 if __name__ == '__main__':