summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/bimap/test/test_bimap_sequenced.cpp
blob: 084ed6504d778dfafe0786c5ca0da2cc661cd0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  VC++ 8.0 warns on usage of certain Standard Library and API functions that
//  can be cause buffer overruns or other possible security issues if misused.
//  See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
//  But the wording of the warning is misleading and unsettling, there are no
//  portable alternative functions, and VC++ 8.0's own libraries use the
//  functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE

#include <boost/config.hpp>

#define BOOST_BIMAP_DISABLE_SERIALIZATION

// Boost.Test
#include <boost/test/minimal.hpp>

// std
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <functional>


// Set type specifications
#include <boost/bimap/list_of.hpp>
#include <boost/bimap/vector_of.hpp>

// bimap container
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/support/lambda.hpp>

#include <libs/bimap/test/test_bimap.hpp>

struct  left_tag {};
struct right_tag {};


template< class Container, class Data >
void test_list_operations(Container & b, Container& c, const Data & d)
{
    c.clear() ;
    c.assign(d.begin(),d.end());
        
    BOOST_CHECK( std::equal( c.begin(), c.end(), d.begin() ) );
    c.reverse();
    BOOST_CHECK( std::equal( c.begin(), c.end(), d.rbegin() ) );

    c.sort();
    BOOST_CHECK( std::equal( c.begin(), c.end(), d.begin() ) );

    c.push_front( *d.begin() );
    BOOST_CHECK( c.size() == d.size()+1 );
    c.unique();
    BOOST_CHECK( c.size() == d.size() );
 
    c.relocate( c.begin(), ++c.begin() );
    c.relocate( c.end(), c.begin(), ++c.begin() );
        
    b.clear();
    c.clear();
    
    c.assign(d.begin(),d.end());
    b.splice(b.begin(),c);

    BOOST_CHECK( c.size() == 0 );
    BOOST_CHECK( b.size() == d.size() );

    c.splice(c.begin(),b,++b.begin());

    BOOST_CHECK( c.size() == 1 );

    c.splice(c.begin(),b,b.begin(),b.end());

    BOOST_CHECK( b.size() == 0 );

    b.assign(d.begin(),d.end());
    c.assign(d.begin(),d.end());
    b.sort();
    c.sort();
    b.merge(c);
    BOOST_CHECK( b.size() == 2*d.size() );
 
    b.unique();
}
    
void test_bimap()
{
    using namespace boost::bimaps;

    typedef std::map<std::string,long> left_data_type;
    left_data_type left_data;
    left_data.insert( left_data_type::value_type("1",1) );
    left_data.insert( left_data_type::value_type("2",2) );
    left_data.insert( left_data_type::value_type("3",3) );
    left_data.insert( left_data_type::value_type("4",4) );

    typedef std::map<long,std::string> right_data_type;
    right_data_type right_data;
    right_data.insert( right_data_type::value_type(1,"1") );
    right_data.insert( right_data_type::value_type(2,"2") );
    right_data.insert( right_data_type::value_type(3,"3") );
    right_data.insert( right_data_type::value_type(4,"4") );


    //--------------------------------------------------------------------
    {
        typedef bimap<
            list_of< std::string >, vector_of< long >
            
        > bm_type;

        std::set< bm_type::value_type > data;
        data.insert( bm_type::value_type("1",1) );
        data.insert( bm_type::value_type("2",2) );
        data.insert( bm_type::value_type("3",3) );
        data.insert( bm_type::value_type("4",4) );

        bm_type b;

        test_bimap_init_copy_swap<bm_type>(data) ;
        test_sequence_container(b,data);
        test_sequence_container(b.left , left_data);
        test_vector_container(b.right,right_data);

        test_mapped_container(b.left );
        test_mapped_container(b.right);

        bm_type c;
        test_list_operations(b,c,data) ;
        test_list_operations(b.left,c.left,left_data) ;
        test_list_operations(b.right,c.right,right_data) ;

        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.remove_if(_key<=bm_type::value_type("1",1));
        c.sort(std::less<bm_type::value_type>());
        b.sort(std::less<bm_type::value_type>());
        c.merge(b,std::less<bm_type::value_type>());
        c.unique(std::equal_to<bm_type::value_type>());
        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.left.remove_if(_key<="1");
        c.left.sort(std::less<std::string>());
        b.left.sort(std::less<std::string>());
        c.left.merge(b.left,std::less<std::string>());
        c.left.unique(std::equal_to<std::string>());
        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.right.remove_if(_key<=1);
        c.right.sort(std::less<long>());
        b.right.sort(std::less<long>());
        c.right.merge(b.right,std::less<long>());
        c.right.unique(std::equal_to<long>());

        c.assign(data.begin(),data.end());
        c.right[0].first = -1;
        c.right.at(0).second = "[1]";
    }
    //--------------------------------------------------------------------

    
    //--------------------------------------------------------------------
    {
        typedef bimap
        <
            vector_of<std::string>, list_of<long>,
            vector_of_relation

        > bm_type;

        std::set< bm_type::value_type > data;
        data.insert( bm_type::value_type("1",1) );
        data.insert( bm_type::value_type("2",2) );
        data.insert( bm_type::value_type("3",3) );
        data.insert( bm_type::value_type("4",4) );
        
        bm_type b;
        
        test_bimap_init_copy_swap<bm_type>(data) ;
        test_vector_container(b,data) ;
        
        bm_type c;
        test_list_operations(b,c,data) ;
        test_list_operations(b.left,c.left,left_data) ;
        test_list_operations(b.right,c.right,right_data) ;
        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.remove_if(_key<=bm_type::value_type("1",1));
        c.sort(std::less<bm_type::value_type>());
        b.sort(std::less<bm_type::value_type>());
        c.merge(b,std::less<bm_type::value_type>());
        c.unique(std::equal_to<bm_type::value_type>());
        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.left.remove_if(_key<="1");
        c.left.sort(std::less<std::string>());
        b.left.sort(std::less<std::string>());
        c.left.merge(b.left,std::less<std::string>());
        c.left.unique(std::equal_to<std::string>());
        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.right.remove_if(_key<=1);
        c.right.sort(std::less<long>());
        b.right.sort(std::less<long>());
        c.right.merge(b.right,std::less<long>());
        c.right.unique(std::equal_to<long>());
        
        c.assign(data.begin(),data.end());
        c[0].left = "(1)";
        c.at(0).right = -1;
        c.left[0].first = "[1]";
        c.left.at(0).second = -1;
    }
    //--------------------------------------------------------------------

    
    //--------------------------------------------------------------------
    {
        typedef bimap
        <
            vector_of<std::string>, list_of<long>,
            list_of_relation

        > bm_type;

        std::set< bm_type::value_type > data;
        data.insert( bm_type::value_type("1",1) );
        data.insert( bm_type::value_type("2",2) );
        data.insert( bm_type::value_type("3",3) );
        data.insert( bm_type::value_type("4",4) );
        
        bm_type b;
        
        test_bimap_init_copy_swap<bm_type>(data) ;
        test_sequence_container(b,data) ;
        
        bm_type c;
        test_list_operations(b,c,data) ;
        test_list_operations(b.left,c.left,left_data) ;
        test_list_operations(b.right,c.right,right_data) ;

        
        c.assign(data.begin(),data.end());
        b.assign(data.begin(),data.end());
        c.remove_if(_key<=bm_type::value_type("1",1));
        c.sort(std::less<bm_type::value_type>());
        b.sort(std::less<bm_type::value_type>());
        c.merge(b,std::less<bm_type::value_type>());
        c.unique(std::equal_to<bm_type::value_type>());
        
        c.assign(data.begin(),data.end());
        c.left[0].first = "[1]";
        c.left.at(0).second = -1;
    }
    //--------------------------------------------------------------------

}


int test_main( int, char* [] )
{
    test_bimap();
    return 0;
}