Line data Source code
1 : //
2 : // Author: Dmitry Saprykin <saprykin.dmitry@gmail.com>, (C) 2013
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #include <vset/multiset.hpp>
8 : #include <fas/testing.hpp>
9 : #include <set>
10 :
11 3 : UNIT(defrag, "")
12 : {
13 :
14 : using namespace fas::testing;
15 : using namespace vset;
16 :
17 : typedef multiset<int, std::greater<int> > multiset_type;
18 1 : multiset_type int_set;
19 :
20 2 : std::set<int> etalon;
21 :
22 10241 : for(int i = 0; i < 10 * 1024; ++i) {
23 10240 : int_set.insert(i);
24 10240 : etalon.insert(i);
25 : }
26 :
27 1 : std::cout << std::endl;
28 221 : for(int i = 0; i < 220; ++i)
29 : {
30 220 : size_t size = 0;
31 220 : size_t size_max = 1;
32 : typedef multiset_type::container_type container_type;
33 220 : container_type& container = int_set.get_container();
34 7071 : for ( container_type::iterator it = container.begin(); it != container.end(); ++it)
35 : {
36 6851 : typename container_type::value_type::second_type second = (*it).second;
37 :
38 6851 : size += second->size();
39 6851 : size_max += second->capacity();
40 : }
41 :
42 220 : t << equal<expect, size_t>( int_set.size(), etalon.size()) << FAS_TESTING_FILE_LINE;
43 220 : t << is_true<expect>( (size * 100)/size_max > 25) << FAS_TESTING_FILE_LINE;;
44 :
45 220 : size_t skip = 0;
46 220 : container_type::iterator it = container.begin();
47 7492 : while( it != container.end() )
48 : {
49 7052 : size_t skipped = 0;
50 7052 : for (; skipped < skip && it != container.end(); ++it, ++skipped);
51 7052 : if( it != container.end() )
52 : {
53 6832 : int erase_item = (*it).second->back();
54 6832 : int_set.erase(erase_item);
55 6832 : etalon.erase(erase_item);
56 6832 : it = container.begin();
57 6832 : skip++;
58 : }
59 : }
60 : }
61 :
62 2 : t << nothing;
63 1 : }
64 :
65 1 : BEGIN_SUITE(defrag_suite, "")
66 : ADD_UNIT(defrag)
67 7 : END_SUITE(defrag_suite)
|