Skip to content

Commit ceb6683

Browse files
committed
Strenghen tests
1 parent 0aea244 commit ceb6683

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

test/test_xsimd_api.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -364,30 +364,32 @@ struct xsimd_api_integral_types_functions
364364
CHECK_EQ(extract(cr), r);
365365
}
366366

367+
/* Test when T is a batch_constant only, not a scalar. */
367368
template <typename U = T>
368-
void test_bitwise_lshift_multiple(typename std::enable_if<!std::is_integral<U>::value, int>::type = 0)
369+
void test_bitwise_lshift_multiple(T const& vals, typename std::enable_if<!std::is_integral<U>::value, int>::type = 0)
369370
{
370371
#ifndef XSIMD_NO_SUPPORTED_ARCHITECTURE
371372
constexpr auto Max = static_cast<value_type>(std::numeric_limits<value_type>::digits);
372373
constexpr auto max_batch = xsimd::make_batch_constant<value_type, Max>();
373374
constexpr auto shifts = xsimd::make_iota_batch_constant<value_type>() % max_batch;
374375

375-
auto shifted = xsimd::bitwise_lshift(T(1), shifts.as_batch());
376-
for (std::size_t i = 0; i < shifts.size; ++i)
377376
{
378-
CHECK_EQ(shifted.get(i), 1 << shifts.get(i));
379-
}
380-
381-
auto shifted_cst = xsimd::bitwise_lshift(T(1), shifts);
382-
for (std::size_t i = 0; i < shifts.size; ++i)
383-
{
384-
CHECK_EQ(shifted_cst.get(i), 1 << shifts.get(i));
377+
auto shifted = xsimd::bitwise_lshift(vals, shifts.as_batch());
378+
auto shifted_cst = xsimd::bitwise_lshift(vals, shifts);
379+
380+
for (std::size_t i = 0; i < shifts.size; ++i)
381+
{
382+
const auto expected = static_cast<value_type>(vals.get(i) << shifts.get(i));
383+
CHECK_EQ(shifted.get(i), expected);
384+
CHECK_EQ(shifted_cst.get(i), expected);
385+
}
385386
}
386387
#endif
387388
}
388389

390+
/* Test multiple does not make sense when T is scalar. */
389391
template <typename U = T>
390-
void test_bitwise_lshift_multiple(typename std::enable_if<std::is_integral<U>::value, int>::type = 0)
392+
void test_bitwise_lshift_multiple(T const&, typename std::enable_if<std::is_integral<U>::value, int>::type = 0)
391393
{
392394
}
393395

@@ -451,7 +453,9 @@ struct xsimd_api_integral_types_functions
451453

452454
TEST_CASE_TEMPLATE("[xsimd api | integral types functions]", B, INTEGRAL_TYPES)
453455
{
454-
xsimd_api_integral_types_functions<B> Test;
456+
using test_type = xsimd_api_integral_types_functions<B>;
457+
458+
test_type Test;
455459

456460
SUBCASE("test_bitwise_lshift_single")
457461
{
@@ -460,7 +464,9 @@ TEST_CASE_TEMPLATE("[xsimd api | integral types functions]", B, INTEGRAL_TYPES)
460464

461465
SUBCASE("bitwise_lshift_multiple")
462466
{
463-
Test.test_bitwise_lshift_multiple();
467+
Test.test_bitwise_lshift_multiple({ 1 });
468+
Test.test_bitwise_lshift_multiple({ 3 });
469+
Test.test_bitwise_lshift_multiple({ 127 });
464470
}
465471

466472
SUBCASE("bitwise_rshift")

0 commit comments

Comments
 (0)