From: cvw Date: Thu, 16 Feb 2012 14:36:57 +0000 (+0000) Subject: test DataArray ElementaryDAThrowAndSpecialCases X-Git-Tag: V6_main_FINAL~853 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55b850705bd7c1f6649c22d735e4884dc4cdf35d;p=tools%2Fmedcoupling.git test DataArray ElementaryDAThrowAndSpecialCases --- diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index 297ae18c0..3fb0d3d99 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -819,6 +819,210 @@ void MEDCouplingBasicsTest3::testKeepSetSelectedComponent2() m1->decrRef(); } +void MEDCouplingBasicsTest3::testElementaryDAThrowAndSpecialCases() +{ + DataArrayInt *da=DataArrayInt::New(); + CPPUNIT_ASSERT_THROW(da->checkAllocated(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(da->fillWithValue(1.),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(da->iota(1),INTERP_KERNEL::Exception); + da->alloc(7,1); + da->fillWithValue(11); //11,11,11,11... + da->iota(10); //10,11,12,13... + + DataArrayInt *db=DataArrayInt::New(); + db->alloc(7,2); + + DataArrayDouble *dbl2=DataArrayDouble::New(); + dbl2->alloc(7,2); + CPPUNIT_ASSERT_THROW(dbl2->isUniform(10.,1e-15),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl2->sort(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl2->reverse(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl2->iota(10.),INTERP_KERNEL::Exception); + + DataArrayDouble *dbl=DataArrayDouble::New(); + //DataArrayDouble not allocated yet + CPPUNIT_ASSERT_THROW(dbl->iota(10.),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->isUniform(10.,1e-15),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->sort(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->reverse(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->fromNoInterlace(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->toNoInterlace(),INTERP_KERNEL::Exception); + + dbl->alloc(7,1); + dbl->iota(10.); + CPPUNIT_ASSERT(!dbl->isUniform(10.,1e-15)); + dbl->sort(); + CPPUNIT_ASSERT(dbl->isMonotonic(true, .99)); + CPPUNIT_ASSERT(dbl->isMonotonic(true, -.99)); + CPPUNIT_ASSERT(!dbl->isMonotonic(true, 1.1)); + CPPUNIT_ASSERT(!dbl->isMonotonic(true, -1.1)); + dbl->reverse(); + CPPUNIT_ASSERT(dbl->isMonotonic(false, .99)); + CPPUNIT_ASSERT(!dbl->isMonotonic(false, 1.1)); + CPPUNIT_ASSERT(!dbl->isMonotonic(false, -1.1)); + + DataArrayInt *dc=DataArrayInt::New(); + dc->alloc(14,1); + + DataArrayDouble *dd=DataArrayDouble::New(); + CPPUNIT_ASSERT_THROW(dd->checkAllocated(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->fillWithValue(1.),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->iota(1.),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!((dd->repr().find("No data"))==std::string::npos)); + + dd->alloc(0,1); //Allocated but nbOfElements==0! + CPPUNIT_ASSERT(!((dd->repr().find("Number of tuples : 0"))==std::string::npos)); + CPPUNIT_ASSERT(!((dd->repr().find("Empty Data"))==std::string::npos)); + dd->fillWithValue(11); //?!... + dd->iota(10); //?!... + CPPUNIT_ASSERT(dd->isMonotonic(true, 1.)); + CPPUNIT_ASSERT(dd->isMonotonic(false, 1.)); + + CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->copyStringInfoFrom(*da),INTERP_KERNEL::Exception); + std::vector cIds(2,2); + CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception); + cIds[0]=1; + cIds[0]=-1; + CPPUNIT_ASSERT_THROW(da->copyPartOfStringInfoFrom(*db,cIds),INTERP_KERNEL::Exception); + + std::vector info(2,"infoOfOneComponent"); + CPPUNIT_ASSERT_THROW(da->setInfoOnComponents(info),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(da->setInfoOnComponent(1,info[0].c_str()),INTERP_KERNEL::Exception); + db->setInfoOnComponents(info); + + CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(-1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(da->getInfoOnComponent(2),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(db->getInfoOnComponent(1)==db->getInfoOnComponent(0)); + CPPUNIT_ASSERT_THROW(db->getVarOnComponent(-1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->getVarOnComponent(2),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(-1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->getUnitOnComponent(2),INTERP_KERNEL::Exception); + + CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname unit "))==std::string("varname unit ")); + CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname]unit["))==std::string("varname]unit[")); + CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("[unit]"))==std::string()); + CPPUNIT_ASSERT(da->GetVarNameFromInfo(std::string("varname [unit]"))==std::string("varname")); + + CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname unit "))==std::string()); + CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname]unit["))==std::string()); + CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("[unit]"))==std::string("unit")); + CPPUNIT_ASSERT(da->GetUnitFromInfo(std::string("varname [unit]"))==std::string("unit")); + + CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*db,"theMessageInThrow"),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->checkNbOfTuplesAndComp(*dc,"theMessageInThrow"),INTERP_KERNEL::Exception); + + CPPUNIT_ASSERT_THROW(da->checkNbOfTuplesAndComp(7,2,"theMessageInThrow"),INTERP_KERNEL::Exception); + da->checkNbOfTuplesAndComp(7,1,"theMessageInThrow"); + + CPPUNIT_ASSERT_THROW(db->checkNbOfElems(7*2+1,"theMessageInThrow"),INTERP_KERNEL::Exception); + db->checkNbOfElems(7*2,"theMessageInThrow"); + + CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(10,9,1,"theMessageInThrow"),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(db->GetNumberOfItemGivenBES(0,1,-1,"theMessageInThrow"),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_EQUAL(10,db->GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow")); + CPPUNIT_ASSERT_EQUAL(5,db->GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow")); + CPPUNIT_ASSERT_EQUAL(6,db->GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow")); + + //std::cout<<"\n!!!!!!!!!\n"<repr()<<"\n!!!!!!!!!\n"; + CPPUNIT_ASSERT(!((da->repr().find("Number of components : 1"))==std::string::npos)); + CPPUNIT_ASSERT(!((dd->repr().find("Number of components : 1"))==std::string::npos)); + CPPUNIT_ASSERT(!((dbl->repr().find("Number of components : 1"))==std::string::npos)); + + CPPUNIT_ASSERT(!((da->reprZip().find("Number of components : 1"))==std::string::npos)); + CPPUNIT_ASSERT(!((dd->reprZip().find("Number of components : 1"))==std::string::npos)); + CPPUNIT_ASSERT(!((dbl->reprZip().find("Number of components : 1"))==std::string::npos)); + + std::ostringstream ret; + dbl->writeVTK(ret,2,"file.tmp"); + CPPUNIT_ASSERT(!((ret.str().find("selectByTupleId2(0,1,-1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->substr(-1,1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->substr(8,1),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->substr(0,8),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->meldWith(dd),INTERP_KERNEL::Exception); + + CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dbl2,da),INTERP_KERNEL::Exception); //dbl dbl2 not have the same number of components + CPPUNIT_ASSERT_THROW(dbl->setPartOfValuesAdv(dd,da),INTERP_KERNEL::Exception); //da tuple selector DataArrayInt instance not have exactly 2 components + + DataArrayDouble *dbl3=DataArrayDouble::New(); + dbl3->alloc(6,2); + dbl3->fillWithValue(11.); + int tupleId; + //bad number of components + CPPUNIT_ASSERT_THROW(dbl3->getMaxValue(tupleId),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->getMaxValue(tupleId),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->getMinValue(tupleId),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->getMinValue(tupleId),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->getAverageValue(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->getAverageValue(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dd->accumulate(100),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl->fromPolarToCart(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->fromCylToCart(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->fromSpherToCart(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->doublyContractedProduct(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->determinant(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->eigenValues(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->eigenVectors(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->inverse(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->trace(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->deviator(),INTERP_KERNEL::Exception); + + dbl3->setIJ(5,1,12.); + CPPUNIT_ASSERT(dbl3->getMaxValueInArray()==12.); + CPPUNIT_ASSERT(dbl3->getMinValueInArray()==11.); + + db->fillWithValue(100); //bad Ids + CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception); + db->fillWithValue(-1); //bad Ids + CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception); + db->fillWithValue(6); //bad Ids for dbl3 + CPPUNIT_ASSERT_THROW(dbl3->setPartOfValuesAdv(dbl2,db),INTERP_KERNEL::Exception); + + DataArrayDouble::SetArrayIn(dbl,dbl3); //dbl->dbl3 memLeaks? + dbl3->checkNoNullValues(); + dbl3->setIJ(6,0,0.); + CPPUNIT_ASSERT_THROW(dbl3->checkNoNullValues(),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(dbl3->applyInv(1.),INTERP_KERNEL::Exception); //div by zero + CPPUNIT_ASSERT_THROW(dbl2->getIdsInRange(1.,2.),INTERP_KERNEL::Exception); + std::vector a(0); //input list must be NON EMPTY + CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception); + + a.push_back(dbl2); + a.push_back(dbl); //Nb of components mismatch + CPPUNIT_ASSERT_THROW(DataArrayDouble::Aggregate(a),INTERP_KERNEL::Exception); + + CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl2,dbl),INTERP_KERNEL::Exception); + + CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl),INTERP_KERNEL::Exception); //Nb of components mismatch + CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl2,dbl2),INTERP_KERNEL::Exception); //Nb of components must be equal to 3 + DataArrayDouble *dbl4=DataArrayDouble::New(); + dbl4->alloc(6,3); + DataArrayDouble *dbl5=DataArrayDouble::New(); + dbl5->alloc(7,3); + CPPUNIT_ASSERT_THROW(DataArrayDouble::CrossProduct(dbl4,dbl5),INTERP_KERNEL::Exception); //Nb of tuples mismatch + + a[0]=dbl4; //Nb of tuple mismatch + a[1]=dbl5; //Nb of tuple mismatch + CPPUNIT_ASSERT_THROW(DataArrayDouble::Meld(a),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT_THROW(DataArrayDouble::Dot(dbl4,dbl5),INTERP_KERNEL::Exception); + + da->decrRef(); + db->decrRef(); + dbl->decrRef(); + dbl2->decrRef(); + dbl3->decrRef(); + dbl4->decrRef(); + dbl5->decrRef(); + dc->decrRef(); + dd->decrRef(); +} + void MEDCouplingBasicsTest3::testDAIGetIdsEqual1() { const int tab1[7]={5,-2,-4,-2,3,2,-2}; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.hxx index 057c1522b..ce5a60944 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.hxx @@ -50,6 +50,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testDataArrayIntInvertO2NNO21 ); CPPUNIT_TEST( testKeepSetSelectedComponent1 ); CPPUNIT_TEST( testKeepSetSelectedComponent2 ); + CPPUNIT_TEST( testElementaryDAThrowAndSpecialCases ); CPPUNIT_TEST( testDAIGetIdsEqual1 ); CPPUNIT_TEST( testDAIGetIdsEqualList1 ); CPPUNIT_TEST( testDAFromNoInterlace1 ); @@ -110,6 +111,7 @@ namespace ParaMEDMEM void testDataArrayIntInvertO2NNO21(); void testKeepSetSelectedComponent1(); void testKeepSetSelectedComponent2(); + void testElementaryDAThrowAndSpecialCases(); void testDAIGetIdsEqual1(); void testDAIGetIdsEqualList1(); void testDAFromNoInterlace1();