]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Test on DataArrayDouble::getMinMaxPerComponent1
authorageay <ageay>
Wed, 2 May 2012 06:32:44 +0000 (06:32 +0000)
committerageay <ageay>
Wed, 2 May 2012 06:32:44 +0000 (06:32 +0000)
src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 76a6da66d2fa85745d411ccc52858ba62d9bd072..d6bce243a9b49325180cc64521f0e404a1c94079 100644 (file)
@@ -905,3 +905,35 @@ void MEDCouplingBasicsTest5::testDataArrayIntRange1()
   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(23,22,0),INTERP_KERNEL::Exception);
   CPPUNIT_ASSERT_THROW(DataArrayInt::Range(22,23,0),INTERP_KERNEL::Exception);
 }
+
+void MEDCouplingBasicsTest5::testDataArrayDoubleGetMinMaxPerComponent1()
+{
+  const double values1[12]={1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.};
+  DataArrayDouble *d1=DataArrayDouble::New();
+  double *res=new double[2*3];
+  CPPUNIT_ASSERT_THROW(d1->getMinMaxPerComponent(res),INTERP_KERNEL::Exception);
+  d1->alloc(4,3);
+  std::copy(values1,values1+12,d1->getPointer());
+  d1->getMinMaxPerComponent(res);
+  const double expected1[6]={-0.9,1.3,1.7,2.1,3.,3.};
+  for(int i=0;i<6;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],res[i],1e-14);
+  delete [] res;
+  //
+  d1->rearrange(2);
+  res=new double[2*2];
+  d1->getMinMaxPerComponent(res);
+  const double expected2[4]={1.,3.,-0.9,3.};
+  for(int i=0;i<4;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],res[i],1e-14);
+  delete [] res;
+  //
+  d1->rearrange(1);
+  res=new double[2*1];
+  d1->getMinMaxPerComponent(res);
+  const double expected3[2]={-0.9,3.};
+  for(int i=0;i<2;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],res[i],1e-14);
+  delete [] res;
+  d1->decrRef();
+}
index 31a33dbffafd57cca0e5c8751acb63903e12b0e6..0d796fd990501a1f038097a5758cb36e01879df2 100644 (file)
@@ -51,6 +51,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testComputeNeighborsOfCells1 );
     CPPUNIT_TEST( testCheckButterflyCellsBug1 );
     CPPUNIT_TEST( testDataArrayIntRange1 );
+    CPPUNIT_TEST( testDataArrayDoubleGetMinMaxPerComponent1 );
     CPPUNIT_TEST_SUITE_END();
   public:
     void testUMeshTessellate2D1();
@@ -69,6 +70,7 @@ namespace ParaMEDMEM
     void testComputeNeighborsOfCells1();
     void testCheckButterflyCellsBug1();
     void testDataArrayIntRange1();
+    void testDataArrayDoubleGetMinMaxPerComponent1();
   };
 }
 
index 77f4b45dc7760038a5843bb7bab39638a9a6cef9..6c2d917a75f578fd6457e73295600003ce49ea88 100644 (file)
@@ -9927,6 +9927,50 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             self.assertEqual(8*[77],f[:,tup].convertToIntArr().getValues())
             pass
         pass
+
+    def testDataArrayDoubleGetMinMaxPerComponent1(self):
+        values1=[1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.]
+        d1=DataArrayDouble.New();
+        self.assertRaises(InterpKernelException,d1.getMinMaxPerComponent)
+        d1=DataArrayDouble.New(values1,4,3);
+        res=d1.getMinMaxPerComponent();
+        self.assertTrue(isinstance(res,list))
+        self.assertEqual(3,len(res))
+        for i in xrange(3):
+            self.assertTrue(isinstance(res[i],tuple))
+            self.assertEqual(2,len(res[i]))
+            pass
+        expected1=[-0.9,1.3,1.7,2.1,3.,3.]
+        for i in xrange(6):
+            self.assertAlmostEqual(expected1[i],res[i/2][i%2],14)
+            pass
+        #
+        d1.rearrange(2);
+        res=d1.getMinMaxPerComponent();
+        self.assertTrue(isinstance(res,list))
+        self.assertEqual(2,len(res))
+        for i in xrange(2):
+            self.assertTrue(isinstance(res[i],tuple))
+            self.assertEqual(2,len(res[i]))
+            pass
+        expected2=[1.,3.,-0.9,3.]
+        for i in xrange(4):
+            self.assertAlmostEqual(expected2[i],res[i/2][i%2],14)
+            pass
+        #
+        d1.rearrange(1);
+        res=d1.getMinMaxPerComponent();
+        self.assertTrue(isinstance(res,list))
+        self.assertEqual(1,len(res))
+        for i in xrange(1):
+            self.assertTrue(isinstance(res[i],tuple))
+            self.assertEqual(2,len(res[i]))
+            pass
+        expected3=[-0.9,3.]
+        for i in xrange(2):
+            self.assertAlmostEqual(expected3[i],res[i/2][i%2],14)
+            pass
+        pass
         
     def setUp(self):
         pass