Line data Source code
1 : //
2 : // Author: Saprykin Dmitry <saprykin.dmitry@gmail.com>, (C) 2014
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #include <fas/testing.hpp>
8 : #include <vset/vtree/vtree.hpp>
9 : #include <vset/vtree/strategy.hpp>
10 :
11 : namespace
12 : {
13 : using namespace vset;
14 :
15 : struct test_type
16 : {
17 : char key;
18 : char value;
19 393 : test_type(): key(0), value(0) {}
20 6 : test_type(char k, char v): key(k), value(v) {}
21 :
22 6 : bool operator==(const test_type &other) const
23 : {
24 6 : return key == other.key && value == other.value;
25 : }
26 : };
27 :
28 : struct cmp_test_type
29 : {
30 105 : bool operator()(const test_type& l, const test_type& r) const
31 : {
32 105 : return l.key < r.key;
33 : }
34 : };
35 :
36 : typedef vtree::vtree< vtree::strategy::vtree_fsb_inmem<test_type, cmp_test_type, 3> > int_vtree;
37 : }
38 :
39 3 : UNIT(vtree_copy_ctor, "")
40 : {
41 : using namespace fas::testing;
42 : using namespace vset;
43 :
44 : //copy constructor is disabled
45 : /*typedef vtree::vtree< vtree::strategy::vtree_fsb_mmap<char, std::less<char>, 3> > ctor_int_vtree;
46 : ctor_int_vtree ctor_tree;
47 : ctor_int_vtree ctor_tree1(ctor_tree);*/
48 :
49 :
50 : //copy ctor + initializer list ctor
51 1 : int_vtree tree;
52 1 : tree.insert(test_type(1,2));
53 1 : tree.insert(test_type(3,4));
54 1 : tree.insert(test_type(5,6));
55 1 : tree.insert(test_type(7,8));
56 :
57 2 : int_vtree tree1(tree);
58 1 : tree1.erase(test_type(3,0));
59 1 : tree1.insert(test_type(3,8));
60 :
61 1 : typename int_vtree::iterator itr1 = tree1.begin();
62 5 : for(typename int_vtree::iterator itr = tree.begin() ;itr != tree.end(); ++itr, ++itr1 )
63 : {
64 4 : if( itr->key == 3 )
65 : {
66 1 : t << equal<expect, char>( itr->value, 4 ) << FAS_TESTING_FILE_LINE;
67 1 : t << equal<expect, char>( itr1->value, 8 ) << FAS_TESTING_FILE_LINE;
68 : }
69 : else
70 : {
71 3 : t << equal<expect, test_type>( *itr, *itr1 ) << FAS_TESTING_FILE_LINE;
72 : }
73 : }
74 :
75 : //move ctor
76 : #ifdef __GXX_EXPERIMENTAL_CXX0X__
77 2 : int_vtree tree2(std::move(tree1));
78 : #else
79 : int_vtree tree2(tree1);
80 : tree1.clear();
81 : #endif
82 :
83 1 : typename int_vtree::iterator itr2 = tree2.begin();
84 5 : for(typename int_vtree::iterator itr = tree.begin(); itr != tree.end(); ++itr, ++itr2 )
85 : {
86 4 : if( itr->key == 3 )
87 : {
88 1 : t << equal<expect, char>( itr->value, 4 ) << FAS_TESTING_FILE_LINE;
89 1 : t << equal<expect, char>( itr2->value, 8 ) << FAS_TESTING_FILE_LINE;
90 : }
91 : else
92 : {
93 3 : t << equal<expect, test_type>( *itr, *itr2 ) << FAS_TESTING_FILE_LINE;
94 : }
95 : }
96 :
97 1 : t << equal<expect, typename int_vtree::size_type>( tree1.size(), static_cast< typename int_vtree::size_type>(0) ) << FAS_TESTING_FILE_LINE;
98 1 : t << equal<expect, typename int_vtree::size_type>( tree2.size(), static_cast< typename int_vtree::size_type>(4) ) << FAS_TESTING_FILE_LINE;
99 :
100 2 : t << nothing;
101 1 : }
102 :
103 1 : BEGIN_SUITE(vtree_ctor_suite, "")
104 : ADD_UNIT(vtree_copy_ctor)
105 7 : END_SUITE(vtree_ctor_suite)
|