]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Tests
authorageay <ageay>
Thu, 10 Jan 2013 13:13:00 +0000 (13:13 +0000)
committerageay <ageay>
Thu, 10 Jan 2013 13:13:00 +0000 (13:13 +0000)
src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 88792eb8bc2791dfd6fc97bb477e1b2717c7b1cd..46ff904521becd95c539be8bb4b8f25653df4026 100644 (file)
@@ -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();
+}
index b7592e737455a6e286b6d6e21583f93b3e0799ab..8e98abff568b81140e846907e5b2feb231c47fcd 100644 (file)
@@ -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();
   };
 }
 
index 346c8b41b09e8d28db875cb2aaabcd036ad11ae1..57744d805dfb471d33305d65c8fff3b0045575d1 100644 (file)
@@ -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