41#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
74 static std::size_t funcalls_;
89 static const char*
name () {
return "Less"; }
92 void operator= (
Less&);
100template <
class T,
class B
idirectIterator,
class Predicate>
105 const BidirectIterator &it,
110 const char*
const itname =
type_name (it, (
T*)0);
111 const char*
const algname = prev ?
"prev_permutation" :
"next_permutation";
112 const char*
const predname = Predicate::name ();
114 const std::size_t
nsrc = std::strlen (src);
116 T*
const xsrc = T::from_char (src,
nsrc);
117 T*
const xsrc_end = xsrc +
nsrc;
119 const BidirectIterator first =
make_iter (xsrc, xsrc, xsrc_end, it);
120 const BidirectIterator
last =
make_iter (xsrc_end, xsrc, xsrc_end, it);
124 const std::size_t last_n_op_assign = T::n_total_op_assign_;
130 std::prev_permutation (first,
last, pred)
131 : std::next_permutation (first,
last, pred);
135 std::prev_permutation (first,
last)
136 : std::next_permutation (first,
last);
139 std::size_t n_ops_assign = T::n_total_op_assign_ - last_n_op_assign;
144 "line %d. %s <%s%{?}, %s%{;}> (\"%s\", ...) == %b, got %b",
145 __LINE__, algname, itname, 0 != ppred, predname,
151 success = xsrc [
i].data_.val_ == dst [
i];
160 "line %d. %s <%s%{?}, %s%{;}> (\"%s\", ...) "
161 "==> got \"%{X=*.*}\", expected \"%s\"",
162 __LINE__, algname, itname, 0 != ppred, predname, src,
163 int (
sizeof (*xsrc)),
int (
nsrc),
int (
i), xsrc, dst);
167 success = n_ops_assign <=
nsrc;
169 "line %d. %s <%s%{?}, %s%{;}> (\"%s\", ...) "
170 "complexity: got %zu assigns, expected no more than %zu",
171 __LINE__, algname, itname, 0 != ppred, predname, src,
179template <
class T,
class B
idirectIterator,
class Predicate>
185 const char*
const itname =
type_name (it, (
T*)0);
186 const char*
const algname = prev ?
"prev_permutation" :
"next_permutation";
187 const char*
const predname = Predicate::name();
190 "std::%s(%s, %2$s%{?}, %s%{;})",
191 algname, itname, 0 != ppred, predname);
193#define TEST(src, dst, res) \
194 test_permutations (__LINE__, src, dst, res, it, (T*)0, ppred, prev)
202 TEST (
"a",
"a",
false);
203 TEST (
"aa",
"aa",
false);
204 TEST (
"ab",
"ba",
false);
205 TEST (
"ba",
"ab",
true);
207 TEST (
"bcaefigjhd",
"bcaefigjdh",
true);
208 TEST (
"bcaefihdgj",
"bcaefigjhd",
true);
210 TEST (
"hefdiacjbg",
"hefdiacgjb",
true);
211 TEST (
"hefdiacjgb",
"hefdiacjbg",
true);
213 TEST (
"aaaaaaaaaa",
"aaaaaaaaaa",
false);
214 TEST (
"aaaaabbbbb",
"bbbbbaaaaa",
false);
215 TEST (
"ababababab",
"abababaabb",
true);
216 TEST (
"bbbbbaaaaa",
"bbbbabaaaa",
true);
218 TEST (
"abcdefghij",
"jihgfedcba",
false);
219 TEST (
"jihgfedcba",
"jihgfedcab",
true);
222 TEST (
"a",
"a",
false);
223 TEST (
"aa",
"aa",
false);
224 TEST (
"ab",
"ba",
true);
225 TEST (
"ba",
"ab",
false);
227 TEST (
"bcaefigjhd",
"bcaefihdgj",
true);
228 TEST (
"bcaefigjdh",
"bcaefigjhd",
true);
230 TEST (
"hefdiacjbg",
"hefdiacjgb",
true);
231 TEST (
"hefdiacgjb",
"hefdiacjbg",
true);
233 TEST (
"aaaaaaaaaa",
"aaaaaaaaaa",
false);
234 TEST (
"aaaaabbbbb",
"aaaababbbb",
true);
235 TEST (
"ababababab",
"ababababba",
true);
236 TEST (
"bbbbbaaaaa",
"aaaaabbbbb",
false);
238 TEST (
"abcdefghij",
"abcdefghji",
true);
239 TEST (
"jihgfedcba",
"abcdefghij",
false);
253template <
class T,
class Predicate>
262 "template <class %s%{?}, class %s%{;}> "
263 "bool %s (%1$s, %1$s%{?}, %s%{;})",
264 "BidirectionalIterator", 0 != ppred,
"Compare",
265 prev ?
"prev_permutation" :
"next_permutation",
266 0 != ppred,
"Compare");
269 rw_note (0, 0, __LINE__,
"BidirectionalIterator test disabled");
276 rw_note (0, 0, __LINE__,
"RandomAccessIterator test disabled");
285template <
class T,
class Predicate>
290 rw_note (0, 0, __LINE__,
"std::prev_permutation test disabled");
297 rw_note (0, 0, __LINE__,
"std::next_permutation test disabled");
311 rw_note (0, 0, __LINE__,
"predicate test disabled");
322int main (
int argc,
char *argv[])
324 return rw_test (argc, argv, __FILE__,
325 "lib.alg.permutation.generators",
328 "|-no-prev_permutation# "
329 "|-no-next_permutation# "
331 "|-no-BidirectionalIterator# "
332 "|-no-RandomAccessIterator#",
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define TEST(src, dst, res)
void test_permutations(int line, const char *src, const char *dst, bool res, const BidirectIterator &it, const T *, const Predicate *ppred, bool prev)
int rw_opt_no_next_permutation
int rw_opt_no_prev_permutation
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, 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 const char * name()
static conv_to_bool make(bool val)