LTP GCOV extension - code coverage report
Current view: directory - testsuite - SimpleTest.cc
Test: STX B+ Tree Testsuite
Date: 2007-05-08 Instrumented lines: 36
Code covered: 97.2 % Executed lines: 35

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

Generated by: LTP GCOV extension version 1.4