From: ageay Date: Wed, 2 May 2012 06:32:44 +0000 (+0000) Subject: Test on DataArrayDouble::getMinMaxPerComponent1 X-Git-Tag: V6_5_0~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cf2e17e3b7c394fb85778e1879d6926afadef08;p=tools%2Fmedcoupling.git Test on DataArrayDouble::getMinMaxPerComponent1 --- diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index 76a6da66d..d6bce243a 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -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(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx index 31a33dbff..0d796fd99 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx @@ -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(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 77f4b45dc..6c2d917a7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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