2 //=============================================================================
4 * @file OrdMultiSet_Test.cpp
6 * This is a simple test of the <ACE_Ordered_MultiSet> and
7 * <ACE_Ordered_MultiSet_Iterator> class templates, instantiating
8 * them with type int. No command line arguments are needed to run
11 * @author Chris Gill <cdgill@cs.wustl.edu>
13 //=============================================================================
16 // Note, for this test the config.h file *must* come first!
17 #include "ace/config-all.h"
19 #include "test_config.h"
20 #include "ace/Containers.h"
24 run_main (int, ACE_TCHAR
*[])
29 ACE_START_TEST (ACE_TEXT ("OrdMultiSet_Test"));
31 // make an empty set of int and an iterator
32 ACE_Ordered_MultiSet
<int> set
;
33 ACE_Ordered_MultiSet_Iterator
<int> iter(set
);
35 // Put in a range of odd ints, without an iterator.
37 for (i
= -10; i
< 10; ++i
)
38 set
.insert (2 * i
+ 1);
40 // Put in an interleaved range of even ints, using an iterator.
41 for (i
= -10; i
<= 10; ++i
)
42 set
.insert (2 * i
, iter
);
44 // Remove the first and last elements of range.
45 while (set
.remove (-20) == 0)
50 while (set
.remove (20) == 0)
55 // Should still have 39 elements in the set.
56 ACE_TEST_ASSERT (set
.is_empty () == 0);
57 ACE_TEST_ASSERT (set
.size () == 39);
59 // Iterate forward through the range we created: should be one of
63 for (i
= -19; i
<= 19; ++i
)
65 // we should still be in the set
66 ACE_TEST_ASSERT (iter
.done () == 0);
68 // make sure the current element is what we expect
70 ACE_TEST_ASSERT (ptr
!= 0);
71 ACE_TEST_ASSERT (*ptr
== i
);
73 // move to the next element in the set
77 // We should have iterated through the entire set.
78 ACE_TEST_ASSERT (iter
.done () != 0);
80 // Iterate backward through the range we created: should be one of
84 for (i
= 19; i
>= -19; --i
)
86 // We should still be in the set.
87 ACE_TEST_ASSERT (iter
.done () == 0);
89 // Make sure the current element is what we expect.
92 ACE_TEST_ASSERT (ptr
!= 0);
93 ACE_TEST_ASSERT (*ptr
== i
);
95 // Move to the previous element in the set.
99 // We should have iterated through the entire set.
100 ACE_TEST_ASSERT (iter
.done () != 0);
102 // Iterate through the set and use the operator* to get the element
105 for (i
= -19; i
<= 19; ++i
)
107 // we should still be in the set
108 ACE_TEST_ASSERT (iter
.done () == 0);
110 // make sure the current element is what we expect
112 ACE_TEST_ASSERT (l
== i
);
114 // move to the next element in the set
118 // We should have iterated through the entire set.
119 ACE_TEST_ASSERT (iter
.done () != 0);
121 // Clear the set, restart the iterator, and make sure the iterator
122 // is out of range at both ends, the set is empty, and a subsequent
123 // advance or retreat on an out of range iterator does not cause
126 ACE_TEST_ASSERT (set
.is_empty () != 0);
128 ACE_TEST_ASSERT (iter
.done () != 0);
131 ACE_TEST_ASSERT (iter
.done () != 0);
134 // Put in a bunch of ints in various relative positions, using an
135 // iterator for the odds and no iterator for the evens.
136 set
.insert (203, iter
);
139 set
.insert (201, iter
);
140 set
.insert (205, iter
);
142 set
.insert (203, iter
);
143 set
.insert (203, iter
);
148 set
.insert (205, iter
);
149 set
.insert (205, iter
);
150 set
.insert (205, iter
);
151 set
.insert (205, iter
);
154 // remove the middle elements
155 while (set
.remove (204) == 0)
160 while (set
.remove (202) == 0)
165 while (set
.remove (203) == 0)
170 // Put the iterator out of range and make sure it stays
171 // that way for finds on the missing elements.
174 set
.find (203, iter
);
175 ACE_TEST_ASSERT (iter
.done () != 0);
176 set
.find (202, iter
);
177 ACE_TEST_ASSERT (iter
.done () != 0);
178 set
.find (204, iter
);
179 ACE_TEST_ASSERT (iter
.done () != 0);
181 // Make sure the other elements can be found.
182 set
.find (205, iter
);
183 ACE_TEST_ASSERT (iter
.done () == 0);
185 ACE_TEST_ASSERT (ptr
!= 0);
186 ACE_TEST_ASSERT (*ptr
== 205);
187 set
.find (201, iter
);
188 ACE_TEST_ASSERT (iter
.done () == 0);
190 ACE_TEST_ASSERT (ptr
!= 0);
191 ACE_TEST_ASSERT (*ptr
== 201);
193 // Finally, iterate through the set and make sure its contents are
194 // correct (one 201 and five 205s).
196 ACE_TEST_ASSERT (iter
.done () == 0);
198 ACE_TEST_ASSERT (ptr
!= 0);
199 ACE_TEST_ASSERT (*ptr
== 201);
202 for (i
= 1; i
<= 5; ++i
)
204 // Should be in the set, able to access the element, value
206 ACE_TEST_ASSERT (iter
.done () == 0);
208 ACE_TEST_ASSERT (ptr
!= 0);
209 ACE_TEST_ASSERT (*ptr
== 205);
211 // Move to the next element in the set.
215 // Should not be anything else in the set.
216 ACE_TEST_ASSERT (iter
.done () != 0);
219 while (set
.remove (205) == 0)
224 while (set
.remove (201) == 0)
229 // Should have no more elements in the set.
230 ACE_TEST_ASSERT (set
.is_empty () != 0);
231 ACE_TEST_ASSERT (set
.size () == 0);
233 ACE_TEST_ASSERT (iter
.done () != 0);
235 ACE_TEST_ASSERT (iter
.done () != 0);