Line data Source code
1 :
2 : /* Copyright (c) 2013, Daniel Nachbaur <daniel.nachbaur@epfl.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include <test.h>
19 : #include <lunchbox/unorderedIntervalSet.h>
20 :
21 1 : int main( int, char** )
22 : {
23 : typedef lunchbox::UnorderedIntervalSet< size_t > SetType;
24 1 : SetType set;
25 1 : TEST( set.empty( ));
26 :
27 1 : set.insert( 2 );
28 1 : TEST( set.size() == 1 );
29 :
30 1 : set.insert( 1, 5 );
31 1 : TEST( set.exists( 3 ));
32 1 : TEST( set.size() == 5 );
33 :
34 1 : set.insert( 1, 5 );
35 1 : TEST( set.size() == 5 );
36 :
37 1 : set.insert( 2, 4 );
38 1 : TEST( set.size() == 5 );
39 :
40 1 : TEST( set.find( 0 ) == set.end( ));
41 1 : TEST( *set.find( 3 ) == 3 );
42 1 : TEST( set.find( 6 ) == set.end( ));
43 :
44 1 : size_t i = 1;
45 6 : for( SetType::const_iterator it = set.begin(); it != set.end(); ++it, ++i )
46 5 : TEST( *it == i );
47 :
48 1 : set.erase( 3, 4 );
49 1 : TEST( set.size() == 3 );
50 :
51 1 : set.erase( 2 );
52 1 : TEST( set.size() == 2 );
53 :
54 1 : TEST( set.exists( 1 ));
55 1 : TEST( set.exists( 5 ));
56 :
57 1 : set.clear();
58 1 : TEST( set.empty( ));
59 :
60 1 : set.insert( 0, 1 );
61 1 : TEST( set.size() == 2 );
62 1 : set.insert( 3, 5 );
63 1 : TEST( set.size() == 5 );
64 1 : SetType::const_iterator it = set.begin();
65 1 : TEST( *it == 0 );
66 1 : ++it;
67 1 : TEST( *it == 1 );
68 1 : ++it;
69 1 : TEST( *it == 3 );
70 1 : ++it;
71 1 : TEST( *it == 4 );
72 1 : ++it;
73 1 : TEST( *it == 5 );
74 :
75 1 : set.erase( 4, 7 );
76 1 : TEST( set.size() == 3 );
77 :
78 1 : set.erase( 40, 70 );
79 1 : TEST( set.size() == 3 );
80 :
81 1 : return EXIT_SUCCESS;
82 3 : }
|