1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2025 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator as a non-empty allocator.
32 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
33 typedef set
<char, less
<char>, my_alloc
> my_set
;
35 const char title01
[] = "Rivers of sand";
36 const char title02
[] = "Concret PH";
37 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
38 const char title04
[] = "never as tired as when i'm waking up";
40 const size_t N1
= sizeof(title01
);
41 const size_t N2
= sizeof(title02
);
42 const size_t N3
= sizeof(title03
);
43 const size_t N4
= sizeof(title04
);
45 const set
<char> set01_ref(title01
, title01
+ N1
);
46 const set
<char> set02_ref(title02
, title02
+ N2
);
47 const set
<char> set03_ref(title03
, title03
+ N3
);
48 const set
<char> set04_ref(title04
, title04
+ N4
);
50 my_set::size_type size01
, size02
;
54 my_set
set01(less
<char>(), alloc01
);
55 size01
= set01
.size();
56 my_set
set02(less
<char>(), alloc01
);
57 size02
= set02
.size();
60 VERIFY( set01
.size() == size02
);
61 VERIFY( set01
.empty() );
62 VERIFY( set02
.size() == size01
);
63 VERIFY( set02
.empty() );
65 my_set
set03(less
<char>(), alloc01
);
66 size01
= set03
.size();
67 my_set
set04(title02
, title02
+ N2
, less
<char>(), alloc01
);
68 size02
= set04
.size();
71 VERIFY( set03
.size() == size02
);
72 VERIFY( equal(set03
.begin(), set03
.end(), set02_ref
.begin()) );
73 VERIFY( set04
.size() == size01
);
74 VERIFY( set04
.empty() );
76 my_set
set05(title01
, title01
+ N1
, less
<char>(), alloc01
);
77 size01
= set05
.size();
78 my_set
set06(title02
, title02
+ N2
, less
<char>(), alloc01
);
79 size02
= set06
.size();
82 VERIFY( set05
.size() == size02
);
83 VERIFY( equal(set05
.begin(), set05
.end(), set02_ref
.begin()) );
84 VERIFY( set06
.size() == size01
);
85 VERIFY( equal(set06
.begin(), set06
.end(), set01_ref
.begin()) );
87 my_set
set07(title01
, title01
+ N1
, less
<char>(), alloc01
);
88 size01
= set07
.size();
89 my_set
set08(title03
, title03
+ N3
, less
<char>(), alloc01
);
90 size02
= set08
.size();
93 VERIFY( set07
.size() == size02
);
94 VERIFY( equal(set07
.begin(), set07
.end(), set03_ref
.begin()) );
95 VERIFY( set08
.size() == size01
);
96 VERIFY( equal(set08
.begin(), set08
.end(), set01_ref
.begin()) );
98 my_set
set09(title03
, title03
+ N3
, less
<char>(), alloc01
);
99 size01
= set09
.size();
100 my_set
set10(title04
, title04
+ N4
, less
<char>(), alloc01
);
101 size02
= set10
.size();
104 VERIFY( set09
.size() == size02
);
105 VERIFY( equal(set09
.begin(), set09
.end(), set04_ref
.begin()) );
106 VERIFY( set10
.size() == size01
);
107 VERIFY( equal(set10
.begin(), set10
.end(), set03_ref
.begin()) );
109 my_set
set11(title04
, title04
+ N4
, less
<char>(), alloc01
);
110 size01
= set11
.size();
111 my_set
set12(title01
, title01
+ N1
, less
<char>(), alloc01
);
112 size02
= set12
.size();
115 VERIFY( set11
.size() == size02
);
116 VERIFY( equal(set11
.begin(), set11
.end(), set01_ref
.begin()) );
117 VERIFY( set12
.size() == size01
);
118 VERIFY( equal(set12
.begin(), set12
.end(), set04_ref
.begin()) );
120 my_set
set13(title03
, title03
+ N3
, less
<char>(), alloc01
);
121 size01
= set13
.size();
122 my_set
set14(title03
, title03
+ N3
, less
<char>(), alloc01
);
123 size02
= set14
.size();
126 VERIFY( set13
.size() == size02
);
127 VERIFY( equal(set13
.begin(), set13
.end(), set03_ref
.begin()) );
128 VERIFY( set14
.size() == size01
);
129 VERIFY( equal(set14
.begin(), set14
.end(), set03_ref
.begin()) );