1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 6.3.4.3 unordered_set::swap
23 #include <tr1/unordered_set>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator as a non-empty allocator.
32 bool test
__attribute__((unused
)) = true;
33 using namespace std::tr1
;
37 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
38 typedef unordered_set
<char, hash
<char>, equal_to
<char>, my_alloc
> my_uset
;
40 const char title01
[] = "Rivers of sand";
41 const char title02
[] = "Concret PH";
42 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
43 const char title04
[] = "never as tired as when i'm waking up";
45 const size_t N1
= sizeof(title01
);
46 const size_t N2
= sizeof(title02
);
47 const size_t N3
= sizeof(title03
);
48 const size_t N4
= sizeof(title04
);
50 typedef set
<char> my_set
;
51 const my_set
set01_ref(title01
, title01
+ N1
);
52 const my_set
set02_ref(title02
, title02
+ N2
);
53 const my_set
set03_ref(title03
, title03
+ N3
);
54 const my_set
set04_ref(title04
, title04
+ N4
);
56 my_uset::size_type size01
, size02
;
60 my_uset
uset01(10, hash
<char>(), equal_to
<char>(), alloc01
);
61 size01
= uset01
.size();
62 my_uset
uset02(10, hash
<char>(), equal_to
<char>(), alloc01
);
63 size02
= uset02
.size();
66 VERIFY( uset01
.size() == size02
);
67 VERIFY( uset01
.empty() );
68 VERIFY( uset02
.size() == size01
);
69 VERIFY( uset02
.empty() );
71 my_uset
uset03(10, hash
<char>(), equal_to
<char>(), alloc01
);
72 size01
= uset03
.size();
73 my_uset
uset04(set02_ref
.begin(), set02_ref
.end(), 10, hash
<char>(),
74 equal_to
<char>(), alloc01
);
75 size02
= uset04
.size();
78 VERIFY( uset03
.size() == size02
);
79 VERIFY( my_set(uset03
.begin(), uset03
.end()) == set02_ref
);
80 VERIFY( uset04
.size() == size01
);
81 VERIFY( uset04
.empty() );
83 my_uset
uset05(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
84 equal_to
<char>(), alloc01
);
85 size01
= uset05
.size();
86 my_uset
uset06(set02_ref
.begin(), set02_ref
.end(), 10, hash
<char>(),
87 equal_to
<char>(), alloc01
);
88 size02
= uset06
.size();
91 VERIFY( uset05
.size() == size02
);
92 VERIFY( my_set(uset05
.begin(), uset05
.end()) == set02_ref
);
93 VERIFY( uset06
.size() == size01
);
94 VERIFY( my_set(uset06
.begin(), uset06
.end()) == set01_ref
);
96 my_uset
uset07(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
97 equal_to
<char>(), alloc01
);
98 size01
= uset07
.size();
99 my_uset
uset08(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
100 equal_to
<char>(), alloc01
);
101 size02
= uset08
.size();
104 VERIFY( uset07
.size() == size02
);
105 VERIFY( my_set(uset07
.begin(), uset07
.end()) == set03_ref
);
106 VERIFY( uset08
.size() == size01
);
107 VERIFY( my_set(uset08
.begin(), uset08
.end()) == set01_ref
);
109 my_uset
uset09(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
110 equal_to
<char>(), alloc01
);
111 size01
= uset09
.size();
112 my_uset
uset10(set04_ref
.begin(), set04_ref
.end(), 10, hash
<char>(),
113 equal_to
<char>(), alloc01
);
114 size02
= uset10
.size();
117 VERIFY( uset09
.size() == size02
);
118 VERIFY( my_set(uset09
.begin(), uset09
.end()) == set04_ref
);
119 VERIFY( uset10
.size() == size01
);
120 VERIFY( my_set(uset10
.begin(), uset10
.end()) == set03_ref
);
122 my_uset
uset11(set04_ref
.begin(), set04_ref
.end(), 10, hash
<char>(),
123 equal_to
<char>(), alloc01
);
124 size01
= uset11
.size();
125 my_uset
uset12(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
126 equal_to
<char>(), alloc01
);
127 size02
= uset12
.size();
130 VERIFY( uset11
.size() == size02
);
131 VERIFY( my_set(uset11
.begin(), uset11
.end()) == set01_ref
);
132 VERIFY( uset12
.size() == size01
);
133 VERIFY( my_set(uset12
.begin(), uset12
.end()) == set04_ref
);
135 my_uset
uset13(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
136 equal_to
<char>(), alloc01
);
137 size01
= uset13
.size();
138 my_uset
uset14(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
139 equal_to
<char>(), alloc01
);
140 size02
= uset14
.size();
143 VERIFY( uset13
.size() == size02
);
144 VERIFY( my_set(uset13
.begin(), uset13
.end()) == set03_ref
);
145 VERIFY( uset14
.size() == size01
);
146 VERIFY( my_set(uset14
.begin(), uset14
.end()) == set03_ref
);