4 #include "cppunit/cppunit_proxy.h"
6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
13 class MultisetTest : public CPPUNIT_NS::TestCase
15 typedef multiset<int, less<int> > mset;
17 CPPUNIT_TEST_SUITE(MultisetTest);
21 CPPUNIT_TEST_SUITE_END();
28 static bool less_than(int a_, int b_)
33 static bool greater_than(int a_, int b_)
39 CPPUNIT_TEST_SUITE_REGISTRATION(MultisetTest);
42 // tests implementation
44 void MultisetTest::mset1()
47 CPPUNIT_ASSERT(s.count(42) == 0);
49 CPPUNIT_ASSERT(s.count(42) == 1);
51 CPPUNIT_ASSERT(s.count(42) == 2);
53 mset::iterator i = s.find(40);
54 CPPUNIT_ASSERT(i == s.end());
57 CPPUNIT_ASSERT(i != s.end());
58 size_t count = s.erase(42);
59 CPPUNIT_ASSERT(count == 2);
61 void MultisetTest::mset3()
63 int array [] = { 3, 6, 1, 2, 3, 2, 6, 7, 9 };
65 //Check iterator on a mutable set
66 mset s(array, array + 9);
69 CPPUNIT_ASSERT(*i == 3);
71 CPPUNIT_ASSERT(*i == 6);
72 pair<mset::iterator, mset::iterator> p = s.equal_range(5);
73 CPPUNIT_ASSERT(*(p.first) == 6);
74 CPPUNIT_ASSERT(*(p.second) == 6);
76 //Check const_iterator on a mutable multiset
77 mset::const_iterator ci;
78 ci = s.lower_bound(3);
79 CPPUNIT_ASSERT(*ci == 3);
80 ci = s.upper_bound(3);
81 CPPUNIT_ASSERT(*ci == 6);
82 pair<mset::const_iterator, mset::const_iterator> cp;
83 #ifdef _STLP_MEMBER_TEMPLATES
84 cp = s.equal_range(5);
85 CPPUNIT_ASSERT(*(cp.first) == 6);
86 CPPUNIT_ASSERT(*(cp.second) == 6);
89 //Check const_iterator on a const multiset
91 ci = crs.lower_bound(3);
92 CPPUNIT_ASSERT(*ci == 3);
93 ci = crs.upper_bound(3);
94 CPPUNIT_ASSERT(*ci == 6);
95 cp = crs.equal_range(5);
96 CPPUNIT_ASSERT(*(cp.first) == 6);
97 CPPUNIT_ASSERT(*(cp.second) == 6);
99 void MultisetTest::mset5()
101 int array [] = { 3, 6, 1, 9 };
104 typedef pointer_to_binary_function<int, int, bool> fn_type;
105 typedef multiset<int, fn_type, allocator<int> > fn_mset;
107 fn_type f(less_than);
108 fn_mset s1(array+0, array + 4 , f );
109 fn_mset::const_iterator i = s1.begin();
110 for (j = 0; i != s1.end(); ++i, ++j) {
111 CPPUNIT_ASSERT(j != 0 || *i == 1);
112 CPPUNIT_ASSERT(j != 1 || *i == 3);
113 CPPUNIT_ASSERT(j != 2 || *i == 6);
114 CPPUNIT_ASSERT(j != 3 || *i == 9);
117 fn_type g(greater_than);
118 fn_mset s2(array, array + 4, g);
120 for (j = 0; i != s2.end(); ++i, ++j) {
121 CPPUNIT_ASSERT(j != 0 || *i == 9);
122 CPPUNIT_ASSERT(j != 1 || *i == 6);
123 CPPUNIT_ASSERT(j != 2 || *i == 3);
124 CPPUNIT_ASSERT(j != 3 || *i == 1);