From 0b9a62d1d35e236b5df6c54c2b00a386dec644d3 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 10 Jan 2013 13:13:00 +0000 Subject: [PATCH] Tests --- .../Test/MEDCouplingBasicsTest5.cxx | 133 ++++++++++++++++++ .../Test/MEDCouplingBasicsTest5.hxx | 4 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 98 +++++++++++++ 3 files changed, 235 insertions(+) diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index 88792eb8b..46ff90452 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -1773,3 +1773,136 @@ void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp6() d1->decrRef(); d2->decrRef(); } + +void MEDCouplingBasicsTest5::testDAIBuildSubstractionOptimized1() +{ + const int tab1[7]={1,3,5,6,7,9,13}; + const int tab2[3]={3,5,9}; + const int tab3[3]={1,3,5}; + DataArrayInt *da1=DataArrayInt::New(); da1->useArray(tab1,false,CPP_DEALLOC,7,1); + DataArrayInt *da2=DataArrayInt::New(); da2->useArray(tab2,false,CPP_DEALLOC,3,1); + DataArrayInt *da3=DataArrayInt::New(); da3->useArray(tab3,false,CPP_DEALLOC,3,1); + DataArrayInt *da4=DataArrayInt::New(); da4->useArray(tab1,false,CPP_DEALLOC,7,1); + // + DataArrayInt *a=0; + a=da1->buildSubstractionOptimized(da2); + CPPUNIT_ASSERT_EQUAL(4,a->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents()); + const int expected1_0[4]={1,6,7,13}; + CPPUNIT_ASSERT(std::equal(expected1_0,expected1_0+4,a->begin())); + a->decrRef(); + // + a=da1->buildSubstractionOptimized(da3); + CPPUNIT_ASSERT_EQUAL(4,a->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents()); + const int expected2_0[4]={6,7,9,13}; + CPPUNIT_ASSERT(std::equal(expected2_0,expected2_0+4,a->begin())); + a->decrRef(); + // + a=da1->buildSubstractionOptimized(da4); + CPPUNIT_ASSERT_EQUAL(0,a->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,a->getNumberOfComponents()); + a->decrRef(); + // + da1->decrRef(); + da2->decrRef(); + da3->decrRef(); + da4->decrRef(); +} + +void MEDCouplingBasicsTest5::testDAIIsStrictlyMonotonic1() +{ + const int tab1[7]={1,3,5,6,7,9,13}; + DataArrayInt *da1=DataArrayInt::New(); da1->useArray(tab1,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(true)); + da1->checkStrictlyMonotonic(true); + CPPUNIT_ASSERT(da1->isMonotonic(true)); + da1->checkMonotonic(true); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(false),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(false),INTERP_KERNEL::Exception); + da1->decrRef(); + // + int tab2[7]={1,3,5,6,6,9,13}; + da1=DataArrayInt::New(); da1->useArray(tab2,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(da1->isMonotonic(true)); + da1->checkMonotonic(true); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(false),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(false),INTERP_KERNEL::Exception); + da1->decrRef(); + // + const int tab3[7]={1,3,5,6,5,9,13}; + da1=DataArrayInt::New(); da1->useArray(tab3,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(false),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(false),INTERP_KERNEL::Exception); + da1->decrRef(); + // + const int tab4[7]={13,9,7,6,5,3,1}; + da1=DataArrayInt::New(); da1->useArray(tab4,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(false)); + da1->checkStrictlyMonotonic(false); + CPPUNIT_ASSERT(da1->isMonotonic(false)); + da1->checkMonotonic(false); + da1->decrRef(); + // + const int tab5[7]={13,9,6,6,5,3,1}; + da1=DataArrayInt::New(); da1->useArray(tab5,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(false),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(da1->isMonotonic(false)); + da1->checkMonotonic(false); + da1->decrRef(); + // + const int tab6[7]={13,9,5,6,5,3,1}; + da1=DataArrayInt::New(); da1->useArray(tab6,false,CPP_DEALLOC,7,1); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(true)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(true),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isStrictlyMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkStrictlyMonotonic(false),INTERP_KERNEL::Exception); + CPPUNIT_ASSERT(!da1->isMonotonic(false)); + CPPUNIT_ASSERT_THROW(da1->checkMonotonic(false),INTERP_KERNEL::Exception); + da1->decrRef(); + // + da1=DataArrayInt::New(); da1->useArray(tab1,false,CPP_DEALLOC,0,1); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(true)); + da1->checkStrictlyMonotonic(true); + CPPUNIT_ASSERT(da1->isMonotonic(true)); + da1->checkMonotonic(true); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(false)); + da1->checkStrictlyMonotonic(false); + CPPUNIT_ASSERT(da1->isMonotonic(false)); + da1->checkMonotonic(false); + da1->decrRef(); + // + da1=DataArrayInt::New(); da1->useArray(tab1,false,CPP_DEALLOC,1,1); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(true)); + da1->checkStrictlyMonotonic(true); + CPPUNIT_ASSERT(da1->isMonotonic(true)); + da1->checkMonotonic(true); + CPPUNIT_ASSERT(da1->isStrictlyMonotonic(false)); + da1->checkStrictlyMonotonic(false); + CPPUNIT_ASSERT(da1->isMonotonic(false)); + da1->checkMonotonic(false); + da1->decrRef(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx index b7592e737..8e98abff5 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx @@ -71,6 +71,8 @@ namespace ParaMEDMEM CPPUNIT_TEST( testDAIPartitionByDifferentValues1 ); CPPUNIT_TEST( testDAICheckMonotonic1 ); CPPUNIT_TEST( testIntersect2DMeshesTmp6 ); + CPPUNIT_TEST( testDAIBuildSubstractionOptimized1 ); + CPPUNIT_TEST( testDAIIsStrictlyMonotonic1 ); CPPUNIT_TEST_SUITE_END(); public: void testUMeshTessellate2D1(); @@ -108,6 +110,8 @@ namespace ParaMEDMEM void testDAIPartitionByDifferentValues1(); void testDAICheckMonotonic1(); void testIntersect2DMeshesTmp6(); + void testDAIBuildSubstractionOptimized1(); + void testDAIIsStrictlyMonotonic1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 346c8b41b..57744d805 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -10633,6 +10633,104 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(0,d.getNbOfElemAllocated()) pass + def testDAIBuildSubstractionOptimized1(self): + da1=DataArrayInt.New([1,3,5,6,7,9,13]) + da2=DataArrayInt.New([3,5,9]) + da3=DataArrayInt.New([1,3,5]) + da4=DataArrayInt.New([1,3,5,6,7,9,13]) + # + a=da1.buildSubstractionOptimized(da2); + self.assertTrue(a.isEqual(DataArrayInt([1,6,7,13]))); + # + a=da1.buildSubstractionOptimized(da3); + self.assertTrue(a.isEqual(DataArrayInt([6,7,9,13]))); + # + a=da1.buildSubstractionOptimized(da4); + self.assertTrue(a.isEqual(DataArrayInt([]))); + pass + + def testDAIIsStrictlyMonotonic1(self): + da1=DataArrayInt.New([1,3,5,6,7,9,13]) + self.assertTrue(da1.isStrictlyMonotonic(True)); + da1.checkStrictlyMonotonic(True); + self.assertTrue(da1.isMonotonic(True)); + da1.checkMonotonic(True); + self.assertTrue(not da1.isStrictlyMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False) + self.assertTrue(not da1.isMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,False) + # + da1=DataArrayInt.New([1,3,5,6,6,9,13]) + self.assertTrue(not da1.isStrictlyMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True) + self.assertTrue(da1.isMonotonic(True)); + da1.checkMonotonic(True); + self.assertTrue(not da1.isStrictlyMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False) + self.assertTrue(not da1.isMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,False) + # + da1=DataArrayInt.New([1,3,5,6,5,9,13]) + self.assertTrue(not da1.isStrictlyMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True) + self.assertTrue(not da1.isMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,True) + self.assertTrue(not da1.isStrictlyMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False) + self.assertTrue(not da1.isMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,False) + # + da1=DataArrayInt.New([13,9,7,6,5,3,1]) + self.assertTrue(not da1.isStrictlyMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True) + self.assertTrue(not da1.isMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,True) + self.assertTrue(da1.isStrictlyMonotonic(False)); + da1.checkStrictlyMonotonic(False); + self.assertTrue(da1.isMonotonic(False)); + da1.checkMonotonic(False); + # + da1=DataArrayInt.New([13,9,6,6,5,3,1]) + self.assertTrue(not da1.isStrictlyMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True) + self.assertTrue(not da1.isMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,True) + self.assertTrue(not da1.isStrictlyMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False) + self.assertTrue(da1.isMonotonic(False)); + da1.checkMonotonic(False); + # + da1=DataArrayInt.New([13,9,5,6,5,3,1]) + self.assertTrue(not da1.isStrictlyMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,True) + self.assertTrue(not da1.isMonotonic(True)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,True) + self.assertTrue(not da1.isStrictlyMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkStrictlyMonotonic,False) + self.assertTrue(not da1.isMonotonic(False)); + self.assertRaises(InterpKernelException,da1.checkMonotonic,False) + # + da1=DataArrayInt.New([]) + self.assertTrue(da1.isStrictlyMonotonic(True)); + da1.checkStrictlyMonotonic(True); + self.assertTrue(da1.isMonotonic(True)); + da1.checkMonotonic(True); + self.assertTrue(da1.isStrictlyMonotonic(False)); + da1.checkStrictlyMonotonic(False); + self.assertTrue(da1.isMonotonic(False)); + da1.checkMonotonic(False); + # + da1=DataArrayInt.New([13]) + self.assertTrue(da1.isStrictlyMonotonic(True)); + da1.checkStrictlyMonotonic(True); + self.assertTrue(da1.isMonotonic(True)); + da1.checkMonotonic(True); + self.assertTrue(da1.isStrictlyMonotonic(False)); + da1.checkStrictlyMonotonic(False); + self.assertTrue(da1.isMonotonic(False)); + da1.checkMonotonic(False); + pass + def setUp(self): pass pass -- 2.39.2