]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_map/operations/count.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_map / operations / count.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
4a6b297c
PC
2
3// 2011-10-28 Paolo Carlini <paolo.carlini@oracle.com>
4
cbe34bb5 5// Copyright (C) 2011-2017 Free Software Foundation, Inc.
4a6b297c
PC
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_map>
24#include <testsuite_hooks.h>
25
26void test01()
27{
4a6b297c
PC
28 using namespace std;
29
30 typedef unordered_map<int, int>::value_type value_type;
31
32 unordered_map<int, int> um0;
33 VERIFY( um0.count(0) == 0 );
34 VERIFY( um0.count(1) == 0 );
35
36 um0.insert(value_type(1, 1));
37 VERIFY( um0.count(0) == 0 );
38 VERIFY( um0.count(1) == 1 );
39
40 um0.insert(value_type(1, 2));
41 VERIFY( um0.count(0) == 0 );
42 VERIFY( um0.count(1) == 1 );
43
44 um0.insert(value_type(2, 1));
45 VERIFY( um0.count(2) == 1 );
46
47 um0.insert(value_type(3, 1));
48 um0.insert(value_type(3, 2));
49 um0.insert(value_type(3, 3));
50 VERIFY( um0.count(3) == 1 );
51
52 um0.erase(2);
53 VERIFY( um0.count(2) == 0 );
54
55 um0.erase(0);
56 VERIFY( um0.count(0) == 0 );
57
58 unordered_map<int, int> um1(um0);
59 VERIFY( um1.count(0) == 0 );
60 VERIFY( um1.count(1) == 1 );
61 VERIFY( um1.count(2) == 0 );
62 VERIFY( um1.count(3) == 1 );
63
64 um0.clear();
65 VERIFY( um0.count(0) == 0 );
66 VERIFY( um0.count(1) == 0 );
67 VERIFY( um0.count(2) == 0 );
68 VERIFY( um0.count(3) == 0 );
69
70 um1.insert(value_type(4, 1));
71 um1.insert(value_type(5, 1));
72 um1.insert(value_type(5, 2));
73 um1.insert(value_type(5, 3));
74 um1.insert(value_type(5, 4));
75 VERIFY( um1.count(4) == 1 );
76 VERIFY( um1.count(5) == 1 );
77
78 um1.erase(1);
79 VERIFY( um1.count(1) == 0 );
80
81 um1.erase(um1.find(5));
82 VERIFY( um1.count(5) == 0 );
83
84 um1.insert(value_type(1, 1));
85 um1.insert(value_type(1, 2));
86 VERIFY( um1.count(1) == 1 );
87
88 um1.erase(5);
89 VERIFY( um1.count(5) == 0 );
90
91 um1.erase(um1.find(4));
92 VERIFY( um1.count(4) == 0 );
93
94 um1.clear();
95 VERIFY( um1.count(0) == 0 );
96 VERIFY( um1.count(1) == 0 );
97 VERIFY( um1.count(2) == 0 );
98 VERIFY( um1.count(3) == 0 );
99 VERIFY( um1.count(4) == 0 );
100 VERIFY( um1.count(5) == 0 );
101}
102
103int main()
104{
105 test01();
106 return 0;
107}