LCOV - code coverage report
Current view: top level - tests/multiset - multiset2_suite.cpp (source / functions) Hit Total Coverage
Test: v-set-coverage.info Lines: 46 48 95.8 %
Date: 2019-09-12 Functions: 13 13 100.0 %

          Line data    Source code
       1             : //
       2             : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
       3             : //
       4             : // Copyright: See COPYING file that comes with this distribution
       5             : //
       6             : 
       7             : #include <vset/multiset.hpp>
       8             : #include <vset/allocators/allocator.hpp>
       9             : #include <vset/allocators/mmap_allocator.hpp>
      10             : #include <vset/allocators/inmem_allocator.hpp>
      11             : #include <fas/testing.hpp>
      12             : #include <set>
      13             : 
      14           3 : UNIT(multiset_alloc, "")
      15             : {
      16             :   using namespace fas::testing;
      17             :   using namespace vset;
      18             : 
      19             :   typedef multiset<int, std::greater<int>, inmem_allocator<512> > multiset_type;
      20           1 :   multiset_type int_set;
      21           1 :   int_set.get_allocator().memory().buffer().reserve(10000000);
      22           1 :   int_set.insert(1);
      23           1 :   int_set.insert(1);
      24           1 :   int_set.insert(1);
      25             : 
      26           1 :   int_set.insert(2);
      27           1 :   int_set.insert(2);
      28           1 :   int_set.insert(2);
      29             : 
      30           1 :   t << equal<expect, size_t>( int_set.size(), 6) << FAS_TESTING_FILE_LINE;
      31             : 
      32           1 :   multiset_type::iterator itr = int_set.find(2);
      33             : 
      34           1 :   int_set.erase(itr);
      35             : 
      36           1 :   t << equal<expect, size_t>( int_set.size(), 5) << FAS_TESTING_FILE_LINE;
      37             : 
      38           1 :   int_set.erase(1);
      39             :   
      40           1 :   t << equal<expect, size_t>( int_set.size(), 2) << FAS_TESTING_FILE_LINE;
      41             : 
      42           1 :   int_set.erase(10);
      43             : 
      44           1 :   t << equal<expect, size_t>( int_set.size(), 2) << FAS_TESTING_FILE_LINE;
      45             : 
      46           1 :   bool flag = true;
      47             :   try
      48             :   {
      49           1 :     int_set.erase(int_set.end());
      50             :   }
      51           0 :   catch(...)
      52             :   {
      53           0 :     flag = false;
      54             :   }
      55             : 
      56           1 :   t << is_true<expect>( flag ) << FAS_TESTING_FILE_LINE;
      57             : 
      58           1 :   t << message("fin");
      59           1 : }
      60             : 
      61           3 : UNIT(multiset2, "")
      62             : {
      63             :   using namespace fas::testing;
      64             :   using namespace vset;
      65             : 
      66             :   // 0,1,2 ; 3,4,5 ; 6,7,8
      67             :   typedef multiset<int, std::greater<int>, allocator<3> > multiset_type;
      68           1 :   multiset_type int_set;
      69          10 :   for (int i=0; i < 9; i++)
      70             :   {
      71           9 :     int_set.insert(i);
      72             :   }
      73             : 
      74          10 :   for (int i=0; i < 9; i++)
      75             :   {
      76           9 :     multiset_type::iterator lower = int_set.lower_bound(i);
      77           9 :     t << equal<expect>( *lower, i) << " i=" << i << " " << FAS_TESTING_FILE_LINE;
      78             :   }
      79             : 
      80          10 :   for (int i=0; i < 9; i++)
      81             :   {
      82           9 :     multiset_type::iterator lower = int_set.upper_bound(i);
      83           9 :     t << equal<expect>( *(--lower), i) << " i=" << i << " " << FAS_TESTING_FILE_LINE;
      84             :   }
      85             : 
      86           6 :   for (int i = 0; i < 9; i += 2)
      87             :   {
      88           5 :     int_set.erase(i);
      89             :   }
      90             : 
      91          10 :   for ( int i=0; i < 9; ++i )
      92             :   {
      93           9 :     multiset_type::iterator lower = int_set.lower_bound(i);
      94           9 :     if ( i == 0 && lower == int_set.end() )
      95           1 :       continue;
      96           8 :     t << is_true<assert>( lower != int_set.end() ) << " i=" << i << " " << FAS_TESTING_FILE_LINE;
      97           8 :     if (i%2!=0)
      98           4 :       t << equal<assert>( *lower, i ) << " i=" << i /*<< "," << i */<< " !="<< *lower<< " " << FAS_TESTING_FILE_LINE;
      99             :     else
     100           4 :       t << equal<assert>( *lower, i-1 ) << " i=" << i-1<< " !="<< *lower<< " " << FAS_TESTING_FILE_LINE;
     101           1 :   }
     102           1 : }
     103             : 
     104             : 
     105           1 : BEGIN_SUITE(multiset2_suite, "")
     106             :   ADD_UNIT(multiset_alloc)
     107             :   ADD_UNIT(multiset2)
     108           7 : END_SUITE(multiset2_suite)

Generated by: LCOV version 1.10