40static std::valarray<std::size_t>
43 std::size_t
buf [256];
50 unsigned long val = std::strtoul (
s, &end, 10);
52 RW_ASSERT (
'\0' == *end ||
',' == *end ||
'@' == *end);
60 const std::size_t
n =
buf [
i-1];
62 for (std::size_t
j = 0;
j < (
val - 1); ++
j)
74 return std::valarray<std::size_t>(
buf,
i);
81 void (std::gslice_array<std::size_t>::*op_assign)(const
std::valarray<
std::size_t>&) const,
86 const char *length_str,
87 const char *stride_str,
94 const std::valarray<std::size_t> lengths (make_array (length_str));
98 const std::valarray<std::size_t> strides (make_array (stride_str));
102 const std::gslice gsl (
start, lengths, strides);
106 std::valarray<std::size_t> lhs_va (make_array (lhs_str));
110 const std::valarray<std::size_t> rhs_va (make_array (rhs_str));
114 const std::valarray<std::size_t> res_va (make_array (res_str));
117 RW_ASSERT (lhs_va.size () == res_va.size ());
120 std::gslice_array<std::size_t> lhs_ga = lhs_va [gsl];
123 std::size_t
size = 0;
128 "gslice_array<%s>(%s) %s std::valarray<%1$s>(%s)",
129 tname, lhs_str, opname, rhs_str);
132 (lhs_ga.*op_assign)(rhs_va);
135 for (std::size_t
i = 0;
i != lhs_va.size (); ++
i) {
137 "line %d. %s: element at index %zu == %zu, got %zu",
138 __LINE__, fname,
i, res_va [
i], lhs_va [
i]))
149#define OP(start, lengths, strides, lhs, rhs, res) \
150 test_op_assign ((T*)0, op, tname, opname, __LINE__, start, lengths, strides, lhs, rhs, res)
157 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
160 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
161 &std::gslice_array<T>::operator*=;
168 OP (0,
"",
"",
"1@4",
"2",
"1@4");
169 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
170 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
171 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
173 OP (0,
"1",
"1",
"1@4",
"5",
"5,1@3");
174 OP (2,
"1",
"1",
"1@4",
"5",
"1,1,5,1");
176 OP (1,
"2",
"1",
"1@4",
"3,4",
"1,3,4,1");
177 OP (1,
"1",
"2",
"2@4",
"2",
"2,4,2,2");
179 OP (0,
"2,1",
"2,3",
"2@4",
"3,7",
"6,2,14,2");
180 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,9,3,3");
189 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
192 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
193 &std::gslice_array<T>::operator/=;
195 OP (0,
"",
"",
"1@4",
"2",
"1@4");
196 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
197 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
198 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
200 OP (0,
"1",
"1",
"10@4",
"5",
"2,10@3");
201 OP (2,
"1",
"1",
"12@4",
"5",
"12,12,2,12");
203 OP (1,
"2",
"1",
"12@4",
"3,4",
"12,4,3,12");
204 OP (1,
"1",
"2",
"6@4",
"2",
"6,3,6,6");
206 OP (0,
"2,1",
"2,3",
"42@4",
"3,7",
"14,42,6,42");
207 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,1,3,3");
216 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
219 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
220 &std::gslice_array<T>::operator%=;
222 OP (0,
"",
"",
"1@4",
"2",
"1@4");
223 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
224 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
225 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
227 OP (0,
"1",
"1",
"10@4",
"5",
"0,10@3");
228 OP (2,
"1",
"1",
"12@4",
"5",
"12,12,2,12");
230 OP (1,
"2",
"1",
"12@4",
"3,4",
"12,0,0,12");
231 OP (1,
"1",
"2",
"7@4",
"2",
"7,1,7,7");
233 OP (0,
"2,1",
"2,3",
"14@4",
"3,7",
"2,14,0,14");
234 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,0,3,3");
243 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
246 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
247 &std::gslice_array<T>::operator+=;
249 OP (0,
"",
"",
"1@4",
"2",
"1@4");
250 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
251 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
252 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
254 OP (0,
"1",
"1",
"1@4",
"5",
"6,1@3");
255 OP (2,
"1",
"1",
"2@4",
"5",
"2,2,7,2");
257 OP (1,
"2",
"1",
"3@4",
"3,4",
"3,6,7,3");
258 OP (1,
"1",
"2",
"7@4",
"2",
"7,9,7,7");
260 OP (0,
"2,1",
"2,3",
"1@4",
"3,7",
"4,1,8,1");
261 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,6,3,3");
270 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
273 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
274 &std::gslice_array<T>::operator-=;
276 OP (0,
"",
"",
"1@4",
"2",
"1@4");
277 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
278 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
279 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
281 OP (0,
"1",
"1",
"9@4",
"5",
"4,9@3");
282 OP (2,
"1",
"1",
"7@4",
"5",
"7,7,2,7");
284 OP (1,
"2",
"1",
"3@4",
"3,2",
"3,0,1,3");
285 OP (1,
"1",
"2",
"7@4",
"2",
"7,5,7,7");
287 OP (0,
"2,1",
"2,3",
"7@4",
"3,7",
"4,7,0,7");
288 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,0,3,3");
297 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
300 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
301 &std::gslice_array<T>::operator^=;
303 OP (0,
"",
"",
"1@4",
"2",
"1@4");
304 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
305 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
306 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
308 OP (0,
"1",
"1",
"9@4",
"5",
"12,9@3");
309 OP (2,
"1",
"1",
"7@4",
"5",
"7,7,2,7");
311 OP (1,
"2",
"1",
"3@4",
"3,4",
"3,0,7,3");
312 OP (1,
"1",
"2",
"7@4",
"2",
"7,5,7,7");
314 OP (0,
"2,1",
"2,3",
"7@4",
"3,7",
"4,7,0,7");
315 OP (1,
"1,0",
"2,3",
"3@4",
"3",
"3,0,3,3");
324 "std::valarray<%s>::operator%s (const std::valarray<%1$s>&)",
327 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
328 &std::gslice_array<T>::operator&=;
330 OP (0,
"",
"",
"1@4",
"2",
"1@4");
331 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
332 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
333 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
335 OP (0,
"1",
"1",
"9@4",
"5",
"1,9@3");
336 OP (2,
"1",
"1",
"7@4",
"5",
"7,7,5,7");
338 OP (1,
"2",
"1",
"3@4",
"3,4",
"3,3,0,3");
339 OP (1,
"1",
"2",
"7@4",
"2",
"7,2,7,7");
341 OP (0,
"2,1",
"2,3",
"7@4",
"3,2",
"3,7,2,7");
342 OP (1,
"1,0",
"2,3",
"3@4",
"1",
"3,1,3,3");
351 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
354 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
355 &std::gslice_array<T>::operator|=;
357 OP (0,
"",
"",
"1@4",
"2",
"1@4");
358 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
359 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
360 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
362 OP (0,
"1",
"1",
"9@4",
"5",
"13,9@3");
363 OP (2,
"1",
"1",
"7@4",
"5",
"7,7,7,7");
365 OP (1,
"2",
"1",
"3@4",
"3,4",
"3,3,7,3");
366 OP (1,
"1",
"2",
"7@4",
"2",
"7,7,7,7");
368 OP (0,
"2,1",
"2,3",
"4@4",
"3,7",
"7,4,7,4");
369 OP (1,
"1,0",
"2,3",
"3@4",
"4",
"3,7,3,3");
378 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
381 void (std::gslice_array<T>::*op)(
const std::valarray<T>&) =
382 &std::gslice_array<T>::operator<<=;
384 OP (0,
"",
"",
"1@4",
"2",
"1@4");
385 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
386 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
387 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
389 OP (0,
"1",
"1",
"1@4",
"1",
"2,1@3");
390 OP (2,
"1",
"1",
"2@4",
"1",
"2,2,4,2");
392 OP (1,
"2",
"1",
"1@4",
"3,4",
"1,4,8,1");
393 OP (1,
"1",
"2",
"3@4",
"2",
"3,12,3,3");
395 OP (0,
"2,1",
"2,3",
"1@4",
"3,2",
"8,1,4,1");
396 OP (1,
"1,0",
"2,3",
"5@4",
"3",
"5,20,5,5");
405 "std::gslice_array<%s>::operator%s (const std::valarray<%1$s>&)",
408 void (std::gslice_array<T>::*op)(
const std::valarray<T>&)
const =
409 &std::gslice_array<T>::operator>>=;
411 OP (0,
"",
"",
"1@4",
"2",
"1@4");
412 OP (0,
"0",
"1",
"1@4",
"2",
"1@4");
413 OP (2,
"0",
"9",
"1@4",
"2",
"1@4");
414 OP (3,
"0",
"2",
"1@4",
"7",
"1@4");
416 OP (0,
"1",
"1",
"1@4",
"1",
"0,1@3");
417 OP (2,
"1",
"1",
"2@4",
"1",
"2,2,1,2");
419 OP (1,
"2",
"1",
"9@4",
"3,4",
"9,1,0,9");
420 OP (1,
"1",
"2",
"9@4",
"2",
"9,2,9,9");
422 OP (0,
"2,1",
"2,3",
"14@4",
"3,2",
"1,14,3,14");
423 OP (1,
"1,0",
"2,3",
"5@4",
"3",
"5,0,5,5");
448 const std::size_t nassigns =
sizeof opt_assign /
sizeof *opt_assign;
449 for (std::size_t
i = 0;
i != nassigns; ++
i) {
450 if (0 < opt_assign [
i]) {
451 for (std::size_t
j = 0;
j != nassigns; ++
j) {
452 if (0 == opt_assign [
j])
460 "tests of operator*= disabled"))
464 "tests of operator/= disabled"))
468 "tests of operator%= disabled"))
472 "tests of operator+= disabled"))
476 "tests of operator-= disabled"))
480 "tests of operator^= disabled"))
484 "tests of operator&= disabled"))
488 "tests of operator|= disabled"))
492 "tests of operator<<= disabled"))
496 "tests of operator>>= disabled"))
506#define TEST(T) test_op_assign ((const T*)0, #T)
530int main (
int argc,
char *argv[])
533 return rw_test (argc, argv, __FILE__,
534 "gslice.array.comp.assign",
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_or_assign(const T *, const char *tname, const char *opname)
void test_op_assign(void *, void(std::gslice_array< std::size_t >::*op_assign)(const std::valarray< std::size_t > &) const, const char *tname, const char *opname, int line, std::size_t start, const char *length_str, const char *stride_str, const char *lhs_str, const char *rhs_str, const char *res_str)
void test_and_assign(const T *, const char *tname, const char *opname)
void test_xor_assign(const T *, const char *tname, const char *opname)
void test_mul_assign(const T *, const char *tname, const char *opname)
#define OP(start, lengths, strides, lhs, rhs, res)
void test_mod_assign(const T *, const char *tname, const char *opname)
void test_shl_assign(const T *, const char *tname, const char *opname)
void test_div_assign(const T *, const char *tname, const char *opname)
void test_shr_assign(const T *, const char *tname, const char *opname)
void test_add_assign(const T *, const char *tname, const char *opname)
void test_sub_assign(const T *, const char *tname, const char *opname)
constexpr std::array< T, sizeof...(Args)> make_array(Args &&... args)
_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 *,...)
_TEST_EXPORT int rw_asnprintf(char **pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt,...)