Skip to content

Commit 3ce8ef4

Browse files
committed
Turn unused aliases in tests into assertions
Several tests declared aliases that were used only in some builds, or not used at all. Where the alias pointed at something worth checking, the test now checks it: - The xassign_traits aliases in test_xcomplex, test_xmath, test_xstrided_view and test_xview were only read under XTENSOR_USE_XSIMD. Without xsimd, simd_linear_assign() is always false, so the tests now assert that in an #else branch. The assign_traits2 check in test_xview expects false in both builds and no longer needs the #if. Note that test_xtensor_core_lib never defines XTENSOR_USE_XSIMD, even in an xsimd build. - test_xview declared carr, a dynamic-rank column-major array, without using it. Add the check the column-major is_contiguous_view comment describes: such a view is not contiguous because implicit trailing all() slices may follow. - test_xexpression only declared the strides aliases of a shared xfunction, one of them under a garbled name. Check that all four come from the shape type, as an xfunction has no strides of its own. Also fix the remaining clang warnings in tests: - test_xmath tested math::abs(char(1)). Plain char is unsigned on aarch64, so the line did not test a signed type there. Use signed char with a negative value. - test_xexpression_holder moved a temporary into the holder, which prevents copy elision. Move a named holder instead, which still exercises the move constructor. - test_xsort passed the axis as {0}. Pass 0.
1 parent 6c8daf4 commit 3ce8ef4

7 files changed

Lines changed: 26 additions & 11 deletions

‎test/test_xcomplex.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ namespace xt
137137

138138
#if XTENSOR_USE_XSIMD
139139
EXPECT_TRUE(assign_t_angle::simd_linear_assign());
140+
#else
141+
EXPECT_FALSE(assign_t_angle::simd_linear_assign());
140142
#endif
141143

142144
auto cmplres_conj = xt::conj(cmplarg_0);
@@ -155,6 +157,8 @@ namespace xt
155157
static_cast<void>(b1);
156158
static_cast<void>(b2);
157159
EXPECT_TRUE(assign_t_conj::simd_linear_assign());
160+
#else
161+
EXPECT_FALSE(assign_t_conj::simd_linear_assign());
158162
#endif
159163

160164
auto cmplres_norm = xt::norm(cmplarg_0);
@@ -168,6 +172,8 @@ namespace xt
168172

169173
#if XTENSOR_USE_XSIMD
170174
EXPECT_TRUE(assign_t_norm::simd_linear_assign());
175+
#else
176+
EXPECT_FALSE(assign_t_norm::simd_linear_assign());
171177
#endif
172178

173179
EXPECT_TRUE(allclose(fieldnorm, cmplres_norm));
@@ -196,6 +202,8 @@ namespace xt
196202

197203
#if XTENSOR_USE_XSIMD
198204
EXPECT_TRUE(assign_t_arg::simd_linear_assign());
205+
#else
206+
EXPECT_FALSE(assign_t_arg::simd_linear_assign());
199207
#endif
200208
}
201209

‎test/test_xexpression.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ namespace xt
102102
buffer << expr1;
103103
EXPECT_EQ(buffer.str(), "{{ 2., 4., 6., 8.},\n { 10., 12., 14., 16.}}");
104104

105-
// Compilation test
105+
// An xfunction has no strides of its own, so the shared expression
106+
// derives all its strides types from its shape type.
106107
auto sexpr1 = make_xshared(std::move(expr1));
107108
using expr_type = decltype(sexpr1);
108-
using strides_type = typename expr_type::strides_type;
109-
using inner_strides_type = typename expr_type::inner_strides_type;
110-
using backstrides_type = typename expr_type::backstrides_type;
111-
using inner_strides_tybackstrides_typepe = typename expr_type::inner_backstrides_type;
109+
using expected_strides_type = get_strides_type<expr_type::shape_type>::type;
110+
EXPECT_TRUE((std::is_same<expr_type::strides_type, expected_strides_type>::value));
111+
EXPECT_TRUE((std::is_same<expr_type::inner_strides_type, expected_strides_type>::value));
112+
EXPECT_TRUE((std::is_same<expr_type::backstrides_type, expected_strides_type>::value));
113+
EXPECT_TRUE((std::is_same<expr_type::inner_backstrides_type, expected_strides_type>::value));
112114
}
113115

114116
TEST(xexpression, shared_expr_return)

‎test/test_xexpression_holder.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace xt
2424

2525
xexpression_holder holder_a = xexpression_holder(a);
2626
xexpression_holder holder_b(b);
27-
xexpression_holder holder_c(std::move(xexpression_holder(c)));
27+
xexpression_holder holder_tmp(c);
28+
xexpression_holder holder_c(std::move(holder_tmp));
2829
}
2930

3031
TEST(xexpression_holder, assign)

‎test/test_xmath.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace xt
4747

4848
#if XTENSOR_USE_XSIMD
4949
EXPECT_TRUE(assign_traits::simd_linear_assign());
50+
#else
51+
EXPECT_FALSE(assign_traits::simd_linear_assign());
5052
#endif
5153
}
5254

@@ -743,7 +745,7 @@ namespace xt
743745
EXPECT_EQ(math::abs(1ul), 1ul);
744746
EXPECT_EQ(math::abs(1u), 1u);
745747
EXPECT_EQ(math::abs(static_cast<unsigned char>(1)), static_cast<unsigned char>(1));
746-
EXPECT_EQ(math::abs(char(1)), 1);
748+
EXPECT_EQ(math::abs(static_cast<signed char>(-1)), 1);
747749
EXPECT_EQ(math::abs(int(1)), 1);
748750
EXPECT_EQ(math::abs(int(-1)), 1);
749751
EXPECT_EQ(math::abs(long(-1)), long(1));

‎test/test_xsort.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace xt
173173
47, 41, 40, 34, 33, 43, 64
174174
};
175175

176-
EXPECT_EQ(ex, xt::argsort(a, {0}, xt::sorting_method::stable));
176+
EXPECT_EQ(ex, xt::argsort(a, 0, xt::sorting_method::stable));
177177
}
178178

179179
TEST(xsort, sort_easy)

‎test/test_xstrided_view.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ namespace xt
691691

692692
#if XTENSOR_USE_XSIMD
693693
EXPECT_TRUE(assign_traits::simd_linear_assign());
694+
#else
695+
EXPECT_FALSE(assign_traits::simd_linear_assign());
694696
#endif
695697

696698
EXPECT_EQ(av, e);

‎test/test_xview.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ namespace xt
13601360

13611361
EXPECT_TRUE((detail::is_contiguous_view<ctes, xall<int>, xall<int>, int, int>()));
13621362
EXPECT_TRUE((detail::is_contiguous_view<cfix, xall<int>, xall<int>, int, int>()));
1363+
EXPECT_FALSE((detail::is_contiguous_view<carr, xall<int>, xall<int>, int, int>()));
13631364
EXPECT_FALSE((detail::is_contiguous_view<xarr, xall<int>, xall<int>, int, int>()));
13641365
EXPECT_TRUE((detail::is_contiguous_view<ctes, xall<int>, xall<int>, xrange<int>, int>()));
13651366
EXPECT_FALSE((detail::is_contiguous_view<ctes, xall<int>, xrange<int>, xrange<int>, int>()));
@@ -1477,13 +1478,12 @@ namespace xt
14771478

14781479
#if XTENSOR_USE_XSIMD
14791480
EXPECT_TRUE(assign_traits::simd_linear_assign());
1481+
#else
1482+
EXPECT_FALSE(assign_traits::simd_linear_assign());
14801483
#endif
14811484

14821485
using assign_traits2 = xassign_traits<decltype(b), decltype(vxa)>;
1483-
1484-
#if XTENSOR_USE_XSIMD
14851486
EXPECT_FALSE(assign_traits2::simd_linear_assign());
1486-
#endif
14871487
}
14881488
}
14891489

0 commit comments

Comments
 (0)