LCOV - code coverage report
Current view: top level - testsuite - StructureTest.cc (source / functions) Hit Total Coverage
Test: STX B+ Tree Testsuite Lines: 30 30 100.0 %
Date: 2011-05-18 Functions: 12 13 92.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: StructureTest.cc 128 2011-05-18 07:23:35Z tb $
       2                 :            : 
       3                 :            : /*
       4                 :            :  * STX B+ Tree Template Classes v0.8.6
       5                 :            :  * Copyright (C) 2008-2011 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 StructureTest : public CPPUNIT_NS::TestFixture
      29 [ +  - ][ #  # ]:          2 : {
      30 [ +  - ][ +  - ]:          2 :     CPPUNIT_TEST_SUITE( StructureTest );
                 [ #  # ]
      31                 :          1 :     CPPUNIT_TEST(test_insert_erase);
      32                 :          2 :     CPPUNIT_TEST_SUITE_END();
      33                 :            : 
      34                 :            : public:
      35                 :            : 
      36                 :            :     struct testdata
      37                 :            :     {
      38                 :            :         unsigned int a, b;
      39                 :            : 
      40                 :            :         // required by the btree
      41                 :      73924 :         testdata()
      42                 :      73924 :             : a(0), b(0)
      43                 :            :         {
      44                 :      73924 :         }
      45                 :            : 
      46                 :            :         // also used as implicit conversion constructor
      47                 :        640 :         inline testdata(unsigned int _a)
      48                 :        640 :             : a(_a), b(0)
      49                 :            :         {
      50                 :        640 :         }
      51                 :            :     };
      52                 :            : 
      53                 :            : protected:
      54                 :            : 
      55                 :            :     struct testcomp
      56                 :            :     {
      57                 :            :         unsigned int somevalue;
      58                 :            : 
      59                 :          1 :         inline testcomp(unsigned int sv)
      60                 :          1 :             : somevalue(sv)
      61                 :            :         {
      62                 :          1 :         }
      63                 :            : 
      64                 :     406708 :         bool operator()(const struct testdata &a, const struct testdata &b) const
      65                 :            :         {
      66                 :     406708 :             return a.a > b.a;
      67                 :            :         }
      68                 :            :     };
      69                 :            : 
      70                 :            :     struct traits_nodebug
      71                 :            :     {
      72                 :            :         static const bool       selfverify = true;
      73                 :            :         static const bool       debug = false;
      74                 :            : 
      75                 :            :         static const int        leafslots = 8;
      76                 :            :         static const int        innerslots = 8;
      77                 :            :     };
      78                 :            : 
      79                 :          1 :     void test_insert_erase()
      80                 :            :     {
      81                 :            :         typedef stx::btree_multiset<struct testdata, struct testcomp, struct traits_nodebug> btree_type;
      82                 :            : 
      83                 :          1 :         btree_type bt( testcomp(42) );
      84                 :            : 
      85                 :          1 :         srand(34234235);
      86         [ +  + ]:        321 :         for(unsigned int i = 0; i < 320; i++)
      87                 :            :         {
      88                 :        320 :             CPPUNIT_ASSERT(bt.size() == i);
      89                 :        320 :             bt.insert(rand() % 100);
      90                 :        320 :             CPPUNIT_ASSERT(bt.size() == i + 1);
      91                 :            :         }
      92                 :            : 
      93                 :          1 :         srand(34234235);
      94         [ +  + ]:        321 :         for(unsigned int i = 0; i < 320; i++)
      95                 :            :         {
      96                 :        320 :             CPPUNIT_ASSERT(bt.size() == 320 - i);
      97                 :        320 :             CPPUNIT_ASSERT( bt.erase_one(rand() % 100) );
      98                 :        320 :             CPPUNIT_ASSERT(bt.size() == 320 - i - 1);
      99                 :          1 :         }
     100                 :          1 :     }
     101                 :            : };
     102                 :            : 
     103                 :            : inline std::ostream& operator<< (std::ostream &o, const struct StructureTest::testdata &t)
     104                 :            : {
     105                 :            :     return o << t.a;
     106                 :            : }
     107                 :            : 
     108 [ +  - ][ +  - ]:          3 : CPPUNIT_TEST_SUITE_REGISTRATION( StructureTest );

Generated by: LCOV version 1.9