1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// $Id: StructureTest.cc 113 2008-09-07 15:25:51Z tb $
/*
* STX B+ Tree Template Classes v0.8.3
* Copyright (C) 2008 Timo Bingmann
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <cppunit/extensions/HelperMacros.h>
#include <stdlib.h>
#include <stx/btree_multiset.h>
class StructureTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( StructureTest );
CPPUNIT_TEST(test_insert_erase);
CPPUNIT_TEST_SUITE_END();
public:
struct testdata
{
unsigned int a, b;
// required by the btree
testdata()
: a(0), b(0)
{
}
// also used as implicit conversion constructor
inline testdata(unsigned int _a)
: a(_a), b(0)
{
}
};
protected:
struct testcomp
{
unsigned int somevalue;
inline testcomp(unsigned int sv)
: somevalue(sv)
{
}
bool operator()(const struct testdata &a, const struct testdata &b) const
{
return a.a > b.a;
}
};
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_insert_erase()
{
typedef stx::btree_multiset<struct testdata, struct testcomp, struct traits_nodebug> btree_type;
btree_type bt( testcomp(42) );
srand(34234235);
for(unsigned int i = 0; i < 320; i++)
{
CPPUNIT_ASSERT(bt.size() == i);
bt.insert(rand() % 100);
CPPUNIT_ASSERT(bt.size() == i + 1);
}
srand(34234235);
for(unsigned int i = 0; i < 320; i++)
{
CPPUNIT_ASSERT(bt.size() == 320 - i);
CPPUNIT_ASSERT( bt.erase_one(rand() % 100) );
CPPUNIT_ASSERT(bt.size() == 320 - i - 1);
}
}
};
inline std::ostream& operator<< (std::ostream &o, const struct StructureTest::testdata &t)
{
return o << t.a;
}
CPPUNIT_TEST_SUITE_REGISTRATION( StructureTest );
|