count.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // 2011-10-28 Paolo Carlini <paolo.carlini@oracle.com>
  2. // Copyright (C) 2011-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License along
  16. // with this library; see the file COPYING3. If not see
  17. // <http://www.gnu.org/licenses/>.
  18. //
  19. #include <set>
  20. #include <testsuite_hooks.h>
  21. void test01()
  22. {
  23. using namespace std;
  24. set<int> s0;
  25. VERIFY( s0.count(0) == 0 );
  26. VERIFY( s0.count(1) == 0 );
  27. s0.insert(1);
  28. VERIFY( s0.count(0) == 0 );
  29. VERIFY( s0.count(1) == 1 );
  30. s0.insert(1);
  31. VERIFY( s0.count(0) == 0 );
  32. VERIFY( s0.count(1) == 1 );
  33. s0.insert(2);
  34. VERIFY( s0.count(2) == 1 );
  35. s0.insert(3);
  36. s0.insert(3);
  37. s0.insert(3);
  38. VERIFY( s0.count(3) == 1 );
  39. s0.erase(2);
  40. VERIFY( s0.count(2) == 0 );
  41. s0.erase(0);
  42. VERIFY( s0.count(0) == 0 );
  43. set<int> s1(s0);
  44. VERIFY( s1.count(0) == 0 );
  45. VERIFY( s1.count(1) == 1 );
  46. VERIFY( s1.count(2) == 0 );
  47. VERIFY( s1.count(3) == 1 );
  48. s0.clear();
  49. VERIFY( s0.count(0) == 0 );
  50. VERIFY( s0.count(1) == 0 );
  51. VERIFY( s0.count(2) == 0 );
  52. VERIFY( s0.count(3) == 0 );
  53. s1.insert(4);
  54. s1.insert(5);
  55. s1.insert(5);
  56. s1.insert(5);
  57. s1.insert(5);
  58. VERIFY( s1.count(4) == 1 );
  59. VERIFY( s1.count(5) == 1 );
  60. s1.erase(1);
  61. VERIFY( s1.count(1) == 0 );
  62. s1.erase(s1.find(5));
  63. VERIFY( s1.count(5) == 0 );
  64. s1.insert(1);
  65. s1.insert(1);
  66. VERIFY( s1.count(1) == 1 );
  67. s1.erase(5);
  68. VERIFY( s1.count(5) == 0 );
  69. s1.erase(s1.find(4));
  70. VERIFY( s1.count(4) == 0 );
  71. s1.clear();
  72. VERIFY( s1.count(0) == 0 );
  73. VERIFY( s1.count(1) == 0 );
  74. VERIFY( s1.count(2) == 0 );
  75. VERIFY( s1.count(3) == 0 );
  76. VERIFY( s1.count(4) == 0 );
  77. VERIFY( s1.count(5) == 0 );
  78. }
  79. int main()
  80. {
  81. test01();
  82. return 0;
  83. }