42#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
80 static const char*
name () {
return "GreaterThanPredicate"; }
92template <
class T,
class Iterator,
class Predicate>
103 const char*
const itname =
type_name (it, (
T*)0);
104 const char*
const fname = stable ?
"stable_partition" :
"partition";
105 const char*
const funname = Predicate::name();
107 const std::size_t
nsrc = std::strlen (src);
108 const std::size_t ndst = std::strlen (dst);
110 T*
const xsrc = T::from_char (src,
nsrc);
111 T*
const xdst = T::from_char (dst, ndst);
113 T*
const xsrc_end = xsrc +
nsrc;
118 const std::size_t last_n_op_assign = T::n_total_op_assign_;
119 const std::size_t t_n_ctors = T::n_total_def_ctor_ + T::n_total_copy_ctor_;
120 const std::size_t t_n_dtors = T::n_total_dtor_;
125 stable ? std::stable_partition (first,
last, pred)
126 : std::partition (first,
last, pred);
129 const std::size_t t_n_objs_diff =
130 T::n_total_def_ctor_ + T::n_total_copy_ctor_
131 - t_n_ctors - T::n_total_dtor_ + t_n_dtors;
133 static const int cwidth =
sizeof (
T);
135 bool success = 0 == t_n_objs_diff;
137 "line %d: std::%s <%s, %s>(\"%s\", ...) ==> \"%{X=*.*}\", "
138 "number of objects changed on %d: %s detected",
139 __LINE__, fname, itname, funname, src,
140 cwidth,
int (
nsrc), -1, xsrc, t_n_objs_diff,
141 t_n_objs_diff > 0 ?
"memory leak" :
"unexpected dtor call");
146 "line %d: std::%s <%s, %s>(\"%s\", ...) ==> \"%{X=*.*}\", "
147 "returned iterator it = first + %td, expected first + %zu",
148 __LINE__, fname, itname, funname, src,
155 success = xsrc[
i].data_.val_ >
value;
161 "line %d: std::%s <%s, %s>(\"%s\", ...) "
162 "==> \"%{X=*.*}\", at %zu got: %#c !> %#c",
163 __LINE__, fname, itname, funname, src,
164 cwidth,
int (
nsrc), -1, xsrc,
i + 1,
165 xsrc[
i].data_.val_,
value);
170 success = xsrc[
i].data_.val_ <=
value;
176 "line %d: std::%s <%s, %s>(\"%s\", ...) "
177 "==> \"%{X=*.*}\", at %zu got: %#c !<= %#c",
178 __LINE__, fname, itname, funname, src,
179 cwidth,
int (
nsrc), -1, xsrc,
i + 1,
180 xsrc[
i].data_.val_,
value);
192 std::size_t op_assigns = T::n_total_op_assign_ - last_n_op_assign;
194 success = op_assigns <= exp_assigns;
196 "line %d: std::%s <%s, %s>(\"%s\", ...): complexity: "
197 "got %zu assignments, expected no more than %zu",
198 __LINE__, fname, itname, funname, src,
199 op_assigns, exp_assigns);
202 success = Predicate::funcalls_ ==
nsrc;
204 "line %d: std::%s <%s, %s>(\"%s\", ...): complexity: "
205 "got %zu applications of the predicate, "
206 "expected no more than %zu",
207 __LINE__, fname, itname, funname, src,
208 Predicate::funcalls_,
nsrc);
214 success = xsrc[
i].data_.val_ == xdst[
i].data_.val_;
220 "line %d: std::%s <%s, %s>(\"%s\", ...) ==> \"%{X=*.*}\", "
221 "expected \"%{X=*.*}\", realtive order broken at %zu, "
223 __LINE__, fname, itname, funname, src,
224 cwidth,
int (
nsrc),
int (
i), xsrc,
225 cwidth,
int (ndst),
int (
i), xdst,
226 i, xsrc[
i].data_.val_, xdst[
i].data_.val_);
235template <
class T,
class Iterator>
240 const char*
const itname =
type_name (it, (
T*)0);
241 const char*
const fname =
242 stable ?
"stable_partition" :
"partition";
246 "%s %s (%1$s, %1$s, %s)",
247 itname, fname, funname);
249#define TEST(src, dest, mid, offet) \
250 test_partitions (__LINE__, src, dest, mid, offet, it, \
251 (GreaterThanPredicate<T>*)0, (T*)0, stable)
254 TEST (
"abcdefghij",
"abcdefghij", 0, 10);
256 TEST (
"abcdefghij",
"bcdefghija",
'a', 9);
257 TEST (
"abcdefghij",
"cdefghijab",
'b', 8);
258 TEST (
"abcdefghij",
"defghijabc",
'c', 7);
259 TEST (
"abcdefghij",
"efghijabcd",
'd', 6);
260 TEST (
"abcdefghij",
"fghijabcde",
'e', 5);
261 TEST (
"abcdefghij",
"ghijabcdef",
'f', 4);
262 TEST (
"abcdefghij",
"hijabcdefg",
'g', 3);
263 TEST (
"abcdefghij",
"ijabcdefgh",
'h', 2);
264 TEST (
"abcdefghij",
"jabcdefghi",
'i', 1);
265 TEST (
"abcdefghij",
"abcdefghij",
'j', 0);
268 TEST (
"jihgfedcba",
"jihgfedcba", 0, 10);
270 TEST (
"jihgfedcba",
"jihgfedcba",
'a', 9);
271 TEST (
"jihgfedcba",
"jihgfedcba",
'b', 8);
272 TEST (
"jihgfedcba",
"jihgfedcba",
'c', 7);
273 TEST (
"jihgfedcba",
"jihgfedcba",
'd', 6);
274 TEST (
"jihgfedcba",
"jihgfedcba",
'e', 5);
275 TEST (
"jihgfedcba",
"jihgfedcba",
'f', 4);
276 TEST (
"jihgfedcba",
"jihgfedcba",
'g', 3);
277 TEST (
"jihgfedcba",
"jihgfedcba",
'h', 2);
278 TEST (
"jihgfedcba",
"jihgfedcba",
'i', 1);
279 TEST (
"jihgfedcba",
"jihgfedcba",
'j', 0);
282 TEST (
"a",
"a", 0, 1);
284 TEST (
"a",
"a",
'a', 0);
299 "template <class %s, class %s> %1$s %s (%1$s, %1$s, %2$s)",
300 "BidirectionalIterator",
"Predicate",
301 stable ?
"stable_partition" :
"partition");
304 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
311 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
323 rw_note (0, __FILE__, __LINE__,
"std::partition test disabled");
330 rw_note (0, __FILE__, __LINE__,
331 "std::stable_partition test disabled");
342int main (
int argc,
char *argv[])
344 return rw_test (argc, argv, __FILE__,
345 "lib.alg.partitions",
348 "|-no-stable_partition# "
349 "|-no-BidirectionalIterator# "
350 "|-no-RandomAccessIterator",
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_partitions(int line, const char *src, const char *dst, const int value, const std::size_t offset, const Iterator &it, const Predicate *, const T *, bool stable)
#define TEST(src, dest, mid, offet)
int rw_opt_no_stable_partition
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, T *)
_TEST_EXPORT unsigned ilog2(_RWSTD_SIZE_T)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
static std::size_t funcalls_
GreaterThanPredicate(int value, int)
static const char * name()
conv_to_bool operator()(const T &arg)
static conv_to_bool make(bool val)