]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_set/operations/count.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / operations / count.cc
1 // { dg-do run { target c++11 } }
2
3 // 2011-10-28 Paolo Carlini <paolo.carlini@oracle.com>
4
5 // Copyright (C) 2011-2024 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21 //
22
23 #include <unordered_set>
24 #include <testsuite_hooks.h>
25
26 void test01()
27 {
28 using namespace std;
29
30 unordered_set<int> us0;
31 VERIFY( us0.count(0) == 0 );
32 VERIFY( us0.count(1) == 0 );
33
34 us0.insert(1);
35 VERIFY( us0.count(0) == 0 );
36 VERIFY( us0.count(1) == 1 );
37
38 us0.insert(1);
39 VERIFY( us0.count(0) == 0 );
40 VERIFY( us0.count(1) == 1 );
41
42 us0.insert(2);
43 VERIFY( us0.count(2) == 1 );
44
45 us0.insert(3);
46 us0.insert(3);
47 us0.insert(3);
48 VERIFY( us0.count(3) == 1 );
49
50 us0.erase(2);
51 VERIFY( us0.count(2) == 0 );
52
53 us0.erase(0);
54 VERIFY( us0.count(0) == 0 );
55
56 unordered_set<int> us1(us0);
57 VERIFY( us1.count(0) == 0 );
58 VERIFY( us1.count(1) == 1 );
59 VERIFY( us1.count(2) == 0 );
60 VERIFY( us1.count(3) == 1 );
61
62 us0.clear();
63 VERIFY( us0.count(0) == 0 );
64 VERIFY( us0.count(1) == 0 );
65 VERIFY( us0.count(2) == 0 );
66 VERIFY( us0.count(3) == 0 );
67
68 us1.insert(4);
69 us1.insert(5);
70 us1.insert(5);
71 us1.insert(5);
72 us1.insert(5);
73 VERIFY( us1.count(4) == 1 );
74 VERIFY( us1.count(5) == 1 );
75
76 us1.erase(1);
77 VERIFY( us1.count(1) == 0 );
78
79 us1.erase(us1.find(5));
80 VERIFY( us1.count(5) == 0 );
81
82 us1.insert(1);
83 us1.insert(1);
84 VERIFY( us1.count(1) == 1 );
85
86 us1.erase(5);
87 VERIFY( us1.count(5) == 0 );
88
89 us1.erase(us1.find(4));
90 VERIFY( us1.count(4) == 0 );
91
92 us1.clear();
93 VERIFY( us1.count(0) == 0 );
94 VERIFY( us1.count(1) == 0 );
95 VERIFY( us1.count(2) == 0 );
96 VERIFY( us1.count(3) == 0 );
97 VERIFY( us1.count(4) == 0 );
98 VERIFY( us1.count(5) == 0 );
99 }
100
101 int main()
102 {
103 test01();
104 return 0;
105 }