Skip to content
Snippets Groups Projects
Forked from Core Modules / dune-common
6829 commits behind the upstream repository.
  • Christian Engwer's avatar
    ad0a6d1e
    * rename blockbitfield to bitsetevector · ad0a6d1e
    Christian Engwer authored
    * make iterators only forwarditertors
    * remove method getLocalBits
    * new methods count and countmasked superseed nSetBits
    * nSetBits marked deprecated, but will stay for a possible
      replacement of BitField by BitSetVector<1> (see #456)
    * updated test to run the whole iterator test
    * fulfill the whole bitset interface
    
    [[Imported from SVN: r5353]]
    ad0a6d1e
    History
    * rename blockbitfield to bitsetevector
    Christian Engwer authored
    * make iterators only forwarditertors
    * remove method getLocalBits
    * new methods count and countmasked superseed nSetBits
    * nSetBits marked deprecated, but will stay for a possible
      replacement of BitField by BitSetVector<1> (see #456)
    * updated test to run the whole iterator test
    * fulfill the whole bitset interface
    
    [[Imported from SVN: r5353]]
bitsetvectortest.cc 2.22 KiB
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include <config.h>

#include <dune/common/bitsetvector.hh>
#ifdef __GNUC__
#include <ext/malloc_allocator.h>
#endif

#include <dune/common/test/iteratortest.hh>

template<class BBF>
struct ConstReferenceOp
{
  typedef typename BBF::value_type bitset;
  typedef typename BBF::const_reference const_reference;

  void operator()(const_reference t){
    bitset x = t[0];
  }
};

template<class BBF>
void testContainer(BBF & bbf)
{
  typedef typename BBF::value_type bitset;
  typedef typename BBF::reference reference;
  typedef typename BBF::const_reference const_reference;

  const BBF & cbbf = bbf;

  bitset x = bbf[3];
  reference y = bbf[4];
  const_reference z = bbf[4];

  // assignement
  y = false;
  y[2] = true;
  y = x;
  x = y;
  x = z;
  y = cbbf[1];
  x = cbbf[1];
  bbf[4] = x;
  bbf[4] = true;

  // equality
  y == cbbf[2];
  y == bbf[3];
  y == x;
  x == y;
  x == z;
  z == x;
  z == y;
  y == z;

  // inequality
  y != cbbf[2];
  y != bbf[3];
  y != x;
  x != y;
  x != z;
  z != x;
  z != y;
  y != z;

  // flip
  y.flip();
  y.flip(2);
  y[3].flip();
}

template<class BBF>
void testConstContainer(const BBF& bbf){
  typedef typename BBF::value_type bitset;
  typedef typename BBF::iterator iterator;
  typedef typename std::iterator_traits<iterator>::value_type value_type;
  typedef typename BBF::const_reference reference;

  const BBF & cbbf = bbf;

  bitset x = bbf[3];
  value_type z;
  reference y = bbf[4];

  // assignement
  x = y;
  x = cbbf[1];

  // equality
  y == cbbf[2];
  y == bbf[3];
  y == x;
  x == y;

  // inequality
  y != cbbf[2];
  y != bbf[3];
  y != x;
  x != y;
}

template<int block_size, class Alloc>
void doTest() {
  typedef Dune::BitSetVector<block_size, Alloc> BBF;

  BBF bbf(10,true);
  const BBF & cbbf = bbf;

  // test containers and some basic bitset operations
  testContainer(bbf);
  testConstContainer(bbf);
  testConstContainer(cbbf);

  // iterator interface
  ConstReferenceOp<BBF> cop;
  assert(testIterator(bbf, cop) == 0);
  assert(testIterator(cbbf, cop) == 0);
}

int main()
{
  doTest<4, std::allocator<bool> >();
#ifdef __GNUC__
  doTest<4, __gnu_cxx::malloc_allocator<bool> >();
#endif
  return 0;
}