From patchwork Fri Oct 28 11:55:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 122397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0FA301007DB for ; Fri, 28 Oct 2011 22:56:23 +1100 (EST) Received: (qmail 13033 invoked by alias); 28 Oct 2011 11:56:17 -0000 Received: (qmail 13015 invoked by uid 22791); 28 Oct 2011 11:56:15 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Oct 2011 11:55:55 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p9SBtrSv027148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Oct 2011 11:55:54 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p9SBtqEx026451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Oct 2011 11:55:53 GMT Received: from abhmt112.oracle.com (abhmt112.oracle.com [141.146.116.64]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p9SBtlsm004035; Fri, 28 Oct 2011 06:55:47 -0500 Received: from [192.168.1.4] (/79.17.190.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 28 Oct 2011 04:55:46 -0700 Message-ID: <4EAA983C.9060209@oracle.com> Date: Fri, 28 Oct 2011 13:55:40 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Add some basic tests for associative/unordered::count() X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, checked x86_64-linux, committed to mainline. Thanks, Paolo. ////////////////////////// 2011-10-28 Paolo Carlini * testsuite/23_containers/unordered_map/operations/count.cc: New. * testsuite/23_containers/multimap/operations/count.cc: Likewise. * testsuite/23_containers/set/operations/count.cc: Likewise. * testsuite/23_containers/unordered_multimap/operations/count.cc: Likewise. * testsuite/23_containers/unordered_set/operations/count.cc: Likewise. * testsuite/23_containers/multiset/operations/count.cc: Likewise. * testsuite/23_containers/unordered_multiset/operations/count.cc: Likewise. * testsuite/23_containers/map/operations/count.cc: Likewise. Index: testsuite/23_containers/unordered_map/operations/count.cc =================================================================== --- testsuite/23_containers/unordered_map/operations/count.cc (revision 0) +++ testsuite/23_containers/unordered_map/operations/count.cc (revision 0) @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef unordered_map::value_type value_type; + + unordered_map um0; + VERIFY( um0.count(0) == 0 ); + VERIFY( um0.count(1) == 0 ); + + um0.insert(value_type(1, 1)); + VERIFY( um0.count(0) == 0 ); + VERIFY( um0.count(1) == 1 ); + + um0.insert(value_type(1, 2)); + VERIFY( um0.count(0) == 0 ); + VERIFY( um0.count(1) == 1 ); + + um0.insert(value_type(2, 1)); + VERIFY( um0.count(2) == 1 ); + + um0.insert(value_type(3, 1)); + um0.insert(value_type(3, 2)); + um0.insert(value_type(3, 3)); + VERIFY( um0.count(3) == 1 ); + + um0.erase(2); + VERIFY( um0.count(2) == 0 ); + + um0.erase(0); + VERIFY( um0.count(0) == 0 ); + + unordered_map um1(um0); + VERIFY( um1.count(0) == 0 ); + VERIFY( um1.count(1) == 1 ); + VERIFY( um1.count(2) == 0 ); + VERIFY( um1.count(3) == 1 ); + + um0.clear(); + VERIFY( um0.count(0) == 0 ); + VERIFY( um0.count(1) == 0 ); + VERIFY( um0.count(2) == 0 ); + VERIFY( um0.count(3) == 0 ); + + um1.insert(value_type(4, 1)); + um1.insert(value_type(5, 1)); + um1.insert(value_type(5, 2)); + um1.insert(value_type(5, 3)); + um1.insert(value_type(5, 4)); + VERIFY( um1.count(4) == 1 ); + VERIFY( um1.count(5) == 1 ); + + um1.erase(1); + VERIFY( um1.count(1) == 0 ); + + um1.erase(um1.find(5)); + VERIFY( um1.count(5) == 0 ); + + um1.insert(value_type(1, 1)); + um1.insert(value_type(1, 2)); + VERIFY( um1.count(1) == 1 ); + + um1.erase(5); + VERIFY( um1.count(5) == 0 ); + + um1.erase(um1.find(4)); + VERIFY( um1.count(4) == 0 ); + + um1.clear(); + VERIFY( um1.count(0) == 0 ); + VERIFY( um1.count(1) == 0 ); + VERIFY( um1.count(2) == 0 ); + VERIFY( um1.count(3) == 0 ); + VERIFY( um1.count(4) == 0 ); + VERIFY( um1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/multimap/operations/count.cc =================================================================== --- testsuite/23_containers/multimap/operations/count.cc (revision 0) +++ testsuite/23_containers/multimap/operations/count.cc (revision 0) @@ -0,0 +1,106 @@ +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef multimap::value_type value_type; + + multimap mm0; + VERIFY( mm0.count(0) == 0 ); + VERIFY( mm0.count(1) == 0 ); + + mm0.insert(value_type(1, 1)); + VERIFY( mm0.count(0) == 0 ); + VERIFY( mm0.count(1) == 1 ); + + mm0.insert(value_type(1, 2)); + VERIFY( mm0.count(0) == 0 ); + VERIFY( mm0.count(1) == 2 ); + + mm0.insert(value_type(2, 1)); + VERIFY( mm0.count(2) == 1 ); + + mm0.insert(value_type(3, 1)); + mm0.insert(value_type(3, 2)); + mm0.insert(value_type(3, 3)); + VERIFY( mm0.count(3) == 3 ); + + mm0.erase(2); + VERIFY( mm0.count(2) == 0 ); + + mm0.erase(0); + VERIFY( mm0.count(0) == 0 ); + + multimap mm1(mm0); + VERIFY( mm1.count(0) == 0 ); + VERIFY( mm1.count(1) == 2 ); + VERIFY( mm1.count(2) == 0 ); + VERIFY( mm1.count(3) == 3 ); + + mm0.clear(); + VERIFY( mm0.count(0) == 0 ); + VERIFY( mm0.count(1) == 0 ); + VERIFY( mm0.count(2) == 0 ); + VERIFY( mm0.count(3) == 0 ); + + mm1.insert(value_type(4, 1)); + mm1.insert(value_type(5, 1)); + mm1.insert(value_type(5, 2)); + mm1.insert(value_type(5, 3)); + mm1.insert(value_type(5, 4)); + VERIFY( mm1.count(4) == 1 ); + VERIFY( mm1.count(5) == 4 ); + + mm1.erase(1); + VERIFY( mm1.count(1) == 0 ); + + mm1.erase(mm1.find(5)); + VERIFY( mm1.count(5) == 3 ); + + mm1.insert(value_type(1, 1)); + mm1.insert(value_type(1, 2)); + VERIFY( mm1.count(1) == 2 ); + + mm1.erase(5); + VERIFY( mm1.count(5) == 0 ); + + mm1.erase(mm1.find(4)); + VERIFY( mm1.count(4) == 0 ); + + mm1.clear(); + VERIFY( mm1.count(0) == 0 ); + VERIFY( mm1.count(1) == 0 ); + VERIFY( mm1.count(2) == 0 ); + VERIFY( mm1.count(3) == 0 ); + VERIFY( mm1.count(4) == 0 ); + VERIFY( mm1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/set/operations/count.cc =================================================================== --- testsuite/23_containers/set/operations/count.cc (revision 0) +++ testsuite/23_containers/set/operations/count.cc (revision 0) @@ -0,0 +1,104 @@ +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + set s0; + VERIFY( s0.count(0) == 0 ); + VERIFY( s0.count(1) == 0 ); + + s0.insert(1); + VERIFY( s0.count(0) == 0 ); + VERIFY( s0.count(1) == 1 ); + + s0.insert(1); + VERIFY( s0.count(0) == 0 ); + VERIFY( s0.count(1) == 1 ); + + s0.insert(2); + VERIFY( s0.count(2) == 1 ); + + s0.insert(3); + s0.insert(3); + s0.insert(3); + VERIFY( s0.count(3) == 1 ); + + s0.erase(2); + VERIFY( s0.count(2) == 0 ); + + s0.erase(0); + VERIFY( s0.count(0) == 0 ); + + set s1(s0); + VERIFY( s1.count(0) == 0 ); + VERIFY( s1.count(1) == 1 ); + VERIFY( s1.count(2) == 0 ); + VERIFY( s1.count(3) == 1 ); + + s0.clear(); + VERIFY( s0.count(0) == 0 ); + VERIFY( s0.count(1) == 0 ); + VERIFY( s0.count(2) == 0 ); + VERIFY( s0.count(3) == 0 ); + + s1.insert(4); + s1.insert(5); + s1.insert(5); + s1.insert(5); + s1.insert(5); + VERIFY( s1.count(4) == 1 ); + VERIFY( s1.count(5) == 1 ); + + s1.erase(1); + VERIFY( s1.count(1) == 0 ); + + s1.erase(s1.find(5)); + VERIFY( s1.count(5) == 0 ); + + s1.insert(1); + s1.insert(1); + VERIFY( s1.count(1) == 1 ); + + s1.erase(5); + VERIFY( s1.count(5) == 0 ); + + s1.erase(s1.find(4)); + VERIFY( s1.count(4) == 0 ); + + s1.clear(); + VERIFY( s1.count(0) == 0 ); + VERIFY( s1.count(1) == 0 ); + VERIFY( s1.count(2) == 0 ); + VERIFY( s1.count(3) == 0 ); + VERIFY( s1.count(4) == 0 ); + VERIFY( s1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_multimap/operations/count.cc =================================================================== --- testsuite/23_containers/unordered_multimap/operations/count.cc (revision 0) +++ testsuite/23_containers/unordered_multimap/operations/count.cc (revision 0) @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef unordered_multimap::value_type value_type; + + unordered_multimap umm0; + VERIFY( umm0.count(0) == 0 ); + VERIFY( umm0.count(1) == 0 ); + + umm0.insert(value_type(1, 1)); + VERIFY( umm0.count(0) == 0 ); + VERIFY( umm0.count(1) == 1 ); + + umm0.insert(value_type(1, 2)); + VERIFY( umm0.count(0) == 0 ); + VERIFY( umm0.count(1) == 2 ); + + umm0.insert(value_type(2, 1)); + VERIFY( umm0.count(2) == 1 ); + + umm0.insert(value_type(3, 1)); + umm0.insert(value_type(3, 2)); + umm0.insert(value_type(3, 3)); + VERIFY( umm0.count(3) == 3 ); + + umm0.erase(2); + VERIFY( umm0.count(2) == 0 ); + + umm0.erase(0); + VERIFY( umm0.count(0) == 0 ); + + unordered_multimap umm1(umm0); + VERIFY( umm1.count(0) == 0 ); + VERIFY( umm1.count(1) == 2 ); + VERIFY( umm1.count(2) == 0 ); + VERIFY( umm1.count(3) == 3 ); + + umm0.clear(); + VERIFY( umm0.count(0) == 0 ); + VERIFY( umm0.count(1) == 0 ); + VERIFY( umm0.count(2) == 0 ); + VERIFY( umm0.count(3) == 0 ); + + umm1.insert(value_type(4, 1)); + umm1.insert(value_type(5, 1)); + umm1.insert(value_type(5, 2)); + umm1.insert(value_type(5, 3)); + umm1.insert(value_type(5, 4)); + VERIFY( umm1.count(4) == 1 ); + VERIFY( umm1.count(5) == 4 ); + + umm1.erase(1); + VERIFY( umm1.count(1) == 0 ); + + umm1.erase(umm1.find(5)); + VERIFY( umm1.count(5) == 3 ); + + umm1.insert(value_type(1, 1)); + umm1.insert(value_type(1, 2)); + VERIFY( umm1.count(1) == 2 ); + + umm1.erase(5); + VERIFY( umm1.count(5) == 0 ); + + umm1.erase(umm1.find(4)); + VERIFY( umm1.count(4) == 0 ); + + umm1.clear(); + VERIFY( umm1.count(0) == 0 ); + VERIFY( umm1.count(1) == 0 ); + VERIFY( umm1.count(2) == 0 ); + VERIFY( umm1.count(3) == 0 ); + VERIFY( umm1.count(4) == 0 ); + VERIFY( umm1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_set/operations/count.cc =================================================================== --- testsuite/23_containers/unordered_set/operations/count.cc (revision 0) +++ testsuite/23_containers/unordered_set/operations/count.cc (revision 0) @@ -0,0 +1,106 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + unordered_set us0; + VERIFY( us0.count(0) == 0 ); + VERIFY( us0.count(1) == 0 ); + + us0.insert(1); + VERIFY( us0.count(0) == 0 ); + VERIFY( us0.count(1) == 1 ); + + us0.insert(1); + VERIFY( us0.count(0) == 0 ); + VERIFY( us0.count(1) == 1 ); + + us0.insert(2); + VERIFY( us0.count(2) == 1 ); + + us0.insert(3); + us0.insert(3); + us0.insert(3); + VERIFY( us0.count(3) == 1 ); + + us0.erase(2); + VERIFY( us0.count(2) == 0 ); + + us0.erase(0); + VERIFY( us0.count(0) == 0 ); + + unordered_set us1(us0); + VERIFY( us1.count(0) == 0 ); + VERIFY( us1.count(1) == 1 ); + VERIFY( us1.count(2) == 0 ); + VERIFY( us1.count(3) == 1 ); + + us0.clear(); + VERIFY( us0.count(0) == 0 ); + VERIFY( us0.count(1) == 0 ); + VERIFY( us0.count(2) == 0 ); + VERIFY( us0.count(3) == 0 ); + + us1.insert(4); + us1.insert(5); + us1.insert(5); + us1.insert(5); + us1.insert(5); + VERIFY( us1.count(4) == 1 ); + VERIFY( us1.count(5) == 1 ); + + us1.erase(1); + VERIFY( us1.count(1) == 0 ); + + us1.erase(us1.find(5)); + VERIFY( us1.count(5) == 0 ); + + us1.insert(1); + us1.insert(1); + VERIFY( us1.count(1) == 1 ); + + us1.erase(5); + VERIFY( us1.count(5) == 0 ); + + us1.erase(us1.find(4)); + VERIFY( us1.count(4) == 0 ); + + us1.clear(); + VERIFY( us1.count(0) == 0 ); + VERIFY( us1.count(1) == 0 ); + VERIFY( us1.count(2) == 0 ); + VERIFY( us1.count(3) == 0 ); + VERIFY( us1.count(4) == 0 ); + VERIFY( us1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/multiset/operations/count.cc =================================================================== --- testsuite/23_containers/multiset/operations/count.cc (revision 0) +++ testsuite/23_containers/multiset/operations/count.cc (revision 0) @@ -0,0 +1,104 @@ +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + multiset ms0; + VERIFY( ms0.count(0) == 0 ); + VERIFY( ms0.count(1) == 0 ); + + ms0.insert(1); + VERIFY( ms0.count(0) == 0 ); + VERIFY( ms0.count(1) == 1 ); + + ms0.insert(1); + VERIFY( ms0.count(0) == 0 ); + VERIFY( ms0.count(1) == 2 ); + + ms0.insert(2); + VERIFY( ms0.count(2) == 1 ); + + ms0.insert(3); + ms0.insert(3); + ms0.insert(3); + VERIFY( ms0.count(3) == 3 ); + + ms0.erase(2); + VERIFY( ms0.count(2) == 0 ); + + ms0.erase(0); + VERIFY( ms0.count(0) == 0 ); + + multiset ms1(ms0); + VERIFY( ms1.count(0) == 0 ); + VERIFY( ms1.count(1) == 2 ); + VERIFY( ms1.count(2) == 0 ); + VERIFY( ms1.count(3) == 3 ); + + ms0.clear(); + VERIFY( ms0.count(0) == 0 ); + VERIFY( ms0.count(1) == 0 ); + VERIFY( ms0.count(2) == 0 ); + VERIFY( ms0.count(3) == 0 ); + + ms1.insert(4); + ms1.insert(5); + ms1.insert(5); + ms1.insert(5); + ms1.insert(5); + VERIFY( ms1.count(4) == 1 ); + VERIFY( ms1.count(5) == 4 ); + + ms1.erase(1); + VERIFY( ms1.count(1) == 0 ); + + ms1.erase(ms1.find(5)); + VERIFY( ms1.count(5) == 3 ); + + ms1.insert(1); + ms1.insert(1); + VERIFY( ms1.count(1) == 2 ); + + ms1.erase(5); + VERIFY( ms1.count(5) == 0 ); + + ms1.erase(ms1.find(4)); + VERIFY( ms1.count(4) == 0 ); + + ms1.clear(); + VERIFY( ms1.count(0) == 0 ); + VERIFY( ms1.count(1) == 0 ); + VERIFY( ms1.count(2) == 0 ); + VERIFY( ms1.count(3) == 0 ); + VERIFY( ms1.count(4) == 0 ); + VERIFY( ms1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_multiset/operations/count.cc =================================================================== --- testsuite/23_containers/unordered_multiset/operations/count.cc (revision 0) +++ testsuite/23_containers/unordered_multiset/operations/count.cc (revision 0) @@ -0,0 +1,106 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + unordered_multiset ums0; + VERIFY( ums0.count(0) == 0 ); + VERIFY( ums0.count(1) == 0 ); + + ums0.insert(1); + VERIFY( ums0.count(0) == 0 ); + VERIFY( ums0.count(1) == 1 ); + + ums0.insert(1); + VERIFY( ums0.count(0) == 0 ); + VERIFY( ums0.count(1) == 2 ); + + ums0.insert(2); + VERIFY( ums0.count(2) == 1 ); + + ums0.insert(3); + ums0.insert(3); + ums0.insert(3); + VERIFY( ums0.count(3) == 3 ); + + ums0.erase(2); + VERIFY( ums0.count(2) == 0 ); + + ums0.erase(0); + VERIFY( ums0.count(0) == 0 ); + + unordered_multiset ums1(ums0); + VERIFY( ums1.count(0) == 0 ); + VERIFY( ums1.count(1) == 2 ); + VERIFY( ums1.count(2) == 0 ); + VERIFY( ums1.count(3) == 3 ); + + ums0.clear(); + VERIFY( ums0.count(0) == 0 ); + VERIFY( ums0.count(1) == 0 ); + VERIFY( ums0.count(2) == 0 ); + VERIFY( ums0.count(3) == 0 ); + + ums1.insert(4); + ums1.insert(5); + ums1.insert(5); + ums1.insert(5); + ums1.insert(5); + VERIFY( ums1.count(4) == 1 ); + VERIFY( ums1.count(5) == 4 ); + + ums1.erase(1); + VERIFY( ums1.count(1) == 0 ); + + ums1.erase(ums1.find(5)); + VERIFY( ums1.count(5) == 3 ); + + ums1.insert(1); + ums1.insert(1); + VERIFY( ums1.count(1) == 2 ); + + ums1.erase(5); + VERIFY( ums1.count(5) == 0 ); + + ums1.erase(ums1.find(4)); + VERIFY( ums1.count(4) == 0 ); + + ums1.clear(); + VERIFY( ums1.count(0) == 0 ); + VERIFY( ums1.count(1) == 0 ); + VERIFY( ums1.count(2) == 0 ); + VERIFY( ums1.count(3) == 0 ); + VERIFY( ums1.count(4) == 0 ); + VERIFY( ums1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/map/operations/count.cc =================================================================== --- testsuite/23_containers/map/operations/count.cc (revision 0) +++ testsuite/23_containers/map/operations/count.cc (revision 0) @@ -0,0 +1,106 @@ +// 2011-10-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef map::value_type value_type; + + map m0; + VERIFY( m0.count(0) == 0 ); + VERIFY( m0.count(1) == 0 ); + + m0.insert(value_type(1, 1)); + VERIFY( m0.count(0) == 0 ); + VERIFY( m0.count(1) == 1 ); + + m0.insert(value_type(1, 2)); + VERIFY( m0.count(0) == 0 ); + VERIFY( m0.count(1) == 1 ); + + m0.insert(value_type(2, 1)); + VERIFY( m0.count(2) == 1 ); + + m0.insert(value_type(3, 1)); + m0.insert(value_type(3, 2)); + m0.insert(value_type(3, 3)); + VERIFY( m0.count(3) == 1 ); + + m0.erase(2); + VERIFY( m0.count(2) == 0 ); + + m0.erase(0); + VERIFY( m0.count(0) == 0 ); + + map m1(m0); + VERIFY( m1.count(0) == 0 ); + VERIFY( m1.count(1) == 1 ); + VERIFY( m1.count(2) == 0 ); + VERIFY( m1.count(3) == 1 ); + + m0.clear(); + VERIFY( m0.count(0) == 0 ); + VERIFY( m0.count(1) == 0 ); + VERIFY( m0.count(2) == 0 ); + VERIFY( m0.count(3) == 0 ); + + m1.insert(value_type(4, 1)); + m1.insert(value_type(5, 1)); + m1.insert(value_type(5, 2)); + m1.insert(value_type(5, 3)); + m1.insert(value_type(5, 4)); + VERIFY( m1.count(4) == 1 ); + VERIFY( m1.count(5) == 1 ); + + m1.erase(1); + VERIFY( m1.count(1) == 0 ); + + m1.erase(m1.find(5)); + VERIFY( m1.count(5) == 0 ); + + m1.insert(value_type(1, 1)); + m1.insert(value_type(1, 2)); + VERIFY( m1.count(1) == 1 ); + + m1.erase(5); + VERIFY( m1.count(5) == 0 ); + + m1.erase(m1.find(4)); + VERIFY( m1.count(4) == 0 ); + + m1.clear(); + VERIFY( m1.count(0) == 0 ); + VERIFY( m1.count(1) == 0 ); + VERIFY( m1.count(2) == 0 ); + VERIFY( m1.count(3) == 0 ); + VERIFY( m1.count(4) == 0 ); + VERIFY( m1.count(5) == 0 ); +} + +int main() +{ + test01(); + return 0; +}