#include <cppunit/extensions/HelperMacros.h>
#include <stdlib.h>
#include <time.h>
#include <stx/btree_multiset.h>
#include <set>
class LargeTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( LargeTest );
CPPUNIT_TEST(test_320_mod_1000);
CPPUNIT_TEST(test_320_mod_10000);
CPPUNIT_TEST(test_3200_mod_10);
CPPUNIT_TEST(test_3200_mod_100);
CPPUNIT_TEST(test_3200_mod_1000);
CPPUNIT_TEST(test_3200_mod_10000);
CPPUNIT_TEST(test_32000_mod_10000);
CPPUNIT_TEST(test_sequence);
CPPUNIT_TEST_SUITE_END();
protected:
struct traits_nodebug
{
static const bool selfverify = true;
static const bool debug = false;
static const int leafslots = 8;
static const int innerslots = 8;
};
void test_multi(const unsigned int insnum, const unsigned int modulo)
{
typedef stx::btree_multiset<unsigned int,
std::less<unsigned int>, struct traits_nodebug> btree_type;
btree_type bt;
typedef std::multiset<unsigned int> multiset_type;
multiset_type set;
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = rand() % modulo;
CPPUNIT_ASSERT( bt.size() == set.size() );
bt.insert(k);
set.insert(k);
CPPUNIT_ASSERT( bt.count(k) == set.count(k) );
CPPUNIT_ASSERT( bt.size() == set.size() );
}
CPPUNIT_ASSERT( bt.size() == insnum );
btree_type::iterator bi = bt.begin();
multiset_type::const_iterator si = set.begin();
for(; bi != bt.end() && si != set.end(); ++bi, ++si)
{
CPPUNIT_ASSERT( *si == bi.key() );
}
CPPUNIT_ASSERT( bi == bt.end() );
CPPUNIT_ASSERT( si == set.end() );
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = rand() % modulo;
CPPUNIT_ASSERT( bt.exists(k) );
}
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = rand() % modulo;
CPPUNIT_ASSERT( bt.count(k) == set.count(k) );
}
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = rand() % modulo;
if (set.find(k) != set.end())
{
CPPUNIT_ASSERT( bt.size() == set.size() );
CPPUNIT_ASSERT( bt.exists(k) );
CPPUNIT_ASSERT( bt.erase_one(k) );
set.erase( set.find(k) );
CPPUNIT_ASSERT( bt.size() == set.size() );
CPPUNIT_ASSERT( std::equal(bt.begin(), bt.end(), set.begin()) );
}
}
CPPUNIT_ASSERT( bt.empty() );
CPPUNIT_ASSERT( set.empty() );
}
void test_320_mod_1000()
{
test_multi(320, 1000);
}
void test_320_mod_10000()
{
test_multi(320, 10000);
}
void test_3200_mod_10()
{
test_multi(3200, 10);
}
void test_3200_mod_100()
{
test_multi(3200, 100);
}
void test_3200_mod_1000()
{
test_multi(3200, 1000);
}
void test_3200_mod_10000()
{
test_multi(3200, 10000);
}
void test_32000_mod_10000()
{
test_multi(32000, 10000);
}
void test_sequence()
{
typedef stx::btree_multiset<unsigned int,
std::less<unsigned int>, struct traits_nodebug> btree_type;
btree_type bt;
const unsigned int insnum = 10000;
typedef std::multiset<unsigned int> multiset_type;
multiset_type set;
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = i;
CPPUNIT_ASSERT( bt.size() == set.size() );
bt.insert(k);
set.insert(k);
CPPUNIT_ASSERT( bt.count(k) == set.count(k) );
CPPUNIT_ASSERT( bt.size() == set.size() );
}
CPPUNIT_ASSERT( bt.size() == insnum );
btree_type::iterator bi = bt.begin();
multiset_type::const_iterator si = set.begin();
for(; bi != bt.end() && si != set.end(); ++bi, ++si)
{
CPPUNIT_ASSERT( *si == bi.key() );
}
CPPUNIT_ASSERT( bi == bt.end() );
CPPUNIT_ASSERT( si == set.end() );
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = i;
CPPUNIT_ASSERT( bt.exists(k) );
}
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = i;
CPPUNIT_ASSERT( bt.count(k) == set.count(k) );
}
srand(34234235);
for(unsigned int i = 0; i < insnum; i++)
{
unsigned int k = i;
if (set.find(k) != set.end())
{
CPPUNIT_ASSERT( bt.size() == set.size() );
CPPUNIT_ASSERT( bt.exists(k) );
CPPUNIT_ASSERT( bt.erase_one(k) );
set.erase( set.find(k) );
CPPUNIT_ASSERT( bt.size() == set.size() );
CPPUNIT_ASSERT( std::equal(bt.begin(), bt.end(), set.begin()) );
}
}
CPPUNIT_ASSERT( bt.empty() );
CPPUNIT_ASSERT( set.empty() );
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( LargeTest );