//
m->decrRef();
}
+
+void MEDCouplingBasicsTest5::testDataArraySort1()
+{
+ DataArrayInt *arr=DataArrayInt::New();
+ CPPUNIT_ASSERT_THROW(arr->sort(true),INTERP_KERNEL::Exception);//no allocation
+ CPPUNIT_ASSERT_THROW(arr->sort(false),INTERP_KERNEL::Exception);//no allocation
+ const int values[6]={2,1,6,5,4,7};
+ arr->alloc(3,2);
+ CPPUNIT_ASSERT_THROW(arr->sort(true),INTERP_KERNEL::Exception);//no one component
+ CPPUNIT_ASSERT_THROW(arr->sort(false),INTERP_KERNEL::Exception);//no one component
+ arr->rearrange(1);
+ std::copy(values,values+6,arr->getPointer());
+ DataArrayInt *arr1=arr->deepCpy();
+ DataArrayInt *arr2=arr->deepCpy();
+ arr1->sort(true);
+ const int expected1[6]={1,2,4,5,6,7};
+ CPPUNIT_ASSERT_EQUAL(6,arr1->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,arr1->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+6,arr1->begin()));
+ arr2->sort(false);
+ const int expected2[6]={7,6,5,4,2,1};
+ CPPUNIT_ASSERT_EQUAL(6,arr2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,arr2->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::equal(expected2,expected2+6,arr2->begin()));
+ arr1->decrRef();
+ arr2->decrRef();
+ arr->decrRef();
+ //
+ DataArrayDouble *ard=DataArrayDouble::New();
+ CPPUNIT_ASSERT_THROW(ard->sort(true),INTERP_KERNEL::Exception);//no allocation
+ CPPUNIT_ASSERT_THROW(ard->sort(false),INTERP_KERNEL::Exception);//no allocation
+ const double valuesD[6]={2.,1.,6.,5.,4.,7.};
+ ard->alloc(3,2);
+ CPPUNIT_ASSERT_THROW(ard->sort(true),INTERP_KERNEL::Exception);//no one component
+ CPPUNIT_ASSERT_THROW(ard->sort(false),INTERP_KERNEL::Exception);//no one component
+ ard->rearrange(1);
+ std::copy(valuesD,valuesD+6,ard->getPointer());
+ DataArrayDouble *ard1=ard->deepCpy();
+ DataArrayDouble *ard2=ard->deepCpy();
+ ard1->sort(true);
+ const double expected3[6]={1.,2.,4.,5.,6.,7.};
+ CPPUNIT_ASSERT_EQUAL(6,ard1->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ard1->getNumberOfComponents());
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected3[i],ard1->getIJ(i,0),1e-12);
+ ard2->sort(false);
+ const double expected4[6]={7.,6.,5.,4.,2.,1.};
+ CPPUNIT_ASSERT_EQUAL(6,ard2->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,ard2->getNumberOfComponents());
+ for(int i=0;i<6;i++)
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(expected4[i],ard2->getIJ(i,0),1e-12);
+ ard1->decrRef();
+ ard2->decrRef();
+ ard->decrRef();
+}
CPPUNIT_TEST( testDataArrayIntGetHashCode1 );
CPPUNIT_TEST( testZipConnectivityPol1 );
CPPUNIT_TEST( testConvexEnvelop2D1 );
+ CPPUNIT_TEST( testDataArraySort1 );
CPPUNIT_TEST_SUITE_END();
public:
void testUMeshTessellate2D1();
void testDataArrayIntGetHashCode1();
void testZipConnectivityPol1();
void testConvexEnvelop2D1();
+ void testDataArraySort1();
};
}
self.assertEqual(4,da.index([12,13]))
pass
+ def testDataArraySort1(self):
+ arr=DataArrayInt.New();
+ self.assertRaises(InterpKernelException,arr.sort,True)
+ self.assertRaises(InterpKernelException,arr.sort,False)
+ values=[2,1,6,5,4,7]
+ arr.alloc(3,2);
+ self.assertRaises(InterpKernelException,arr.sort,True)
+ self.assertRaises(InterpKernelException,arr.sort,False)
+ arr.rearrange(1);
+ arr.setValues(values,6,1)
+ arr1=arr.deepCpy();
+ arr2=arr.deepCpy();
+ arr1.sort(True);
+ expected1=[1,2,4,5,6,7]
+ self.assertEqual(6,arr1.getNumberOfTuples());
+ self.assertEqual(1,arr1.getNumberOfComponents());
+ self.assertEqual(expected1,arr1.getValues());
+ arr2.sort(False);
+ expected2=[7,6,5,4,2,1]
+ self.assertEqual(6,arr2.getNumberOfTuples());
+ self.assertEqual(1,arr2.getNumberOfComponents());
+ self.assertTrue(expected2,arr2.getValues());
+ #
+ ard=DataArrayDouble.New();
+ self.assertRaises(InterpKernelException,ard.sort,True)
+ self.assertRaises(InterpKernelException,ard.sort,False)
+ valuesD=[2.,1.,6.,5.,4.,7.]
+ ard.alloc(3,2);
+ self.assertRaises(InterpKernelException,ard.sort,True)
+ self.assertRaises(InterpKernelException,ard.sort,False)
+ ard.rearrange(1);
+ ard.setValues(valuesD,6,1)
+ ard1=ard.deepCpy();
+ ard2=ard.deepCpy();
+ ard1.sort(True);
+ expected3=[1.,2.,4.,5.,6.,7.]
+ self.assertEqual(6,ard1.getNumberOfTuples());
+ self.assertEqual(1,ard1.getNumberOfComponents());
+ for i in xrange(6):
+ self.assertAlmostEqual(expected3[i],ard1.getIJ(i,0),12)
+ pass
+ ard2.sort(False);
+ expected4=[7.,6.,5.,4.,2.,1.]
+ self.assertEqual(6,ard2.getNumberOfTuples());
+ self.assertEqual(1,ard2.getNumberOfComponents());
+ for i in xrange(6):
+ self.assertAlmostEqual(expected4[i],ard2.getIJ(i,0),12)
+ pass
+ pass
+
def setUp(self):
pass
pass