예제 #1
0
int main()
{
  typedef Labels<80, DGtal::uint32_t> MyLabels;
  typedef MyLabels::ConstIterator LabelsConstIterator;
  typedef std::bitset<80> MyBitset;

  BOOST_CONCEPT_ASSERT(( boost::ForwardIterator< LabelsConstIterator > ));

  unsigned int nb = 0;
  unsigned int nbok = 0;
  trace.beginBlock ( "Testing Labels" );
  MyLabels l;
  MyBitset v;
  ++nb, nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  insert( v, l, 15 );
  insert( v, l, 4 );
  ++nb, nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  insert( v, l, 62 );
  insert( v, l, 4 );
  insert( v, l, 78 );
  insert( v, l, 31 );
  insert( v, l, 32 );
  ++nb, nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  checkInsert( v, l, 40 );
  ++nb, nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  checkErase( v, l, 200 );
  ++nb, nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  for ( LabelsConstIterator it = l.begin(), it_end = l.end();
        it != it_end; ++it )
    std::cout << " " << *it;
  std::cout << std::endl;
  trace.endBlock();
  return ( nb == nbok ) ? 0 : 1;
}
예제 #2
0
int main()
{
  typedef Labels<80, DGtal::uint32_t> MyLabels;
  typedef MyLabels::ConstIterator LabelsConstIterator;
  typedef std::bitset<80> MyBitset;

  BOOST_CONCEPT_ASSERT(( boost::ForwardIterator< LabelsConstIterator > ));

  unsigned int nb = 0;
  unsigned int nbok = 0;
  trace.beginBlock ( "Testing Labels" );
  MyLabels l;
  MyBitset v;
  ++nb; nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  insert( v, l, 15 );
  insert( v, l, 4 );
  ++nb; nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  insert( v, l, 62 );
  insert( v, l, 4 );
  insert( v, l, 78 );
  insert( v, l, 31 );
  insert( v, l, 32 );
  ++nb; nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  checkInsert( v, l, 40 );
  ++nb; nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl; 
  checkErase( v, l, 200 );
  ++nb; nbok += isEqual( v, l ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
  for ( LabelsConstIterator it = l.begin(), it_end = l.end();
        it != it_end; ++it )
    std::cout << " " << *it;
  std::cout << std::endl;

  trace.endBlock();

  // Test related to pull request #971 & #972
  typedef Labels<32, DGtal::uint32_t> MySmallLabels;
  typedef MySmallLabels::ConstIterator SmallLabelsConstIterator;
  typedef std::bitset<32> MySmallBitset;
  
  trace.beginBlock ( "Testing one word long Labels" );
  MySmallLabels ll;
  MySmallBitset vv;

  ++nb; nbok += isEqual( vv, ll ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l=" << ll << std::endl; 

  insert( vv, ll, 15 );
  insert( vv, ll, 4 );
  insert( vv, ll, 31 );
  ++nb; nbok += isEqual( vv, ll ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l=" << ll << std::endl; 

  erase( vv, ll, 15 );
  ++nb; nbok += isEqual( vv, ll ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l=" << ll << std::endl; 
  
  // Check insertion at index 0
  insert( vv, ll, 0 );
  ++nb; nbok += isEqual( vv, ll ) ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l=" << ll << std::endl; 

  // Check bit count computation
  ++nb; nbok += ll.count() == 3 ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l.count()=" << ll.count() << std::endl;

  // Compare with size computed with iterators
  unsigned int cnt = 0;
  for ( SmallLabelsConstIterator it = ll.begin(), it_end = ll.end(); it != it_end; ++cnt, ++it) {}
  ++nb; nbok += cnt == 3 ? 1 : 0;
  std::cout << "(" << nbok << "/" << nb << ") small_l bit count with iterators=" << cnt << std::endl;
  
  trace.endBlock();

  return ( nb == nbok ) ? 0 : 1;
}