Skip to content

Commit 889d843

Browse files
Properly test batch and batch_bool constructors
Fix #103
1 parent 8315905 commit 889d843

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

test/test_batch.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,35 @@ struct batch_test
7373
CHECK_EQ(ares, rhs);
7474
}
7575

76+
template <size_t... Is>
77+
struct pack
78+
{
79+
};
80+
81+
template <size_t... Values>
82+
void check_constructor_from_sequence(std::integral_constant<size_t, 0>, pack<Values...>) const
83+
{
84+
array_type tmp = { static_cast<value_type>(Values)... };
85+
batch_type b0(static_cast<value_type>(Values)...);
86+
INFO("batch(values...)");
87+
CHECK_EQ(b0, tmp);
88+
89+
batch_type b1 { static_cast<value_type>(Values)... };
90+
INFO("batch{values...}");
91+
CHECK_EQ(b0, tmp);
92+
}
93+
94+
template <size_t I, size_t... Values>
95+
void check_constructor_from_sequence(std::integral_constant<size_t, I>, pack<Values...>) const
96+
{
97+
return check_constructor_from_sequence(std::integral_constant<size_t, I - 1>(), pack<Values..., I>());
98+
}
99+
76100
void test_constructors() const
77101
{
102+
batch_type b;
103+
// value initialized to random data, can't be checked
104+
78105
array_type tmp;
79106
std::fill(tmp.begin(), tmp.end(), value_type(2));
80107
batch_type b0a(2);
@@ -85,9 +112,7 @@ struct batch_test
85112
INFO("batch{value_type}");
86113
CHECK_EQ(b0b, tmp);
87114

88-
batch_type b1 = batch_type::load_unaligned(lhs.data());
89-
INFO("batch(value_type*)");
90-
CHECK_EQ(b1, lhs);
115+
check_constructor_from_sequence(std::integral_constant<size_t, size>(), pack<>());
91116
}
92117

93118
void test_static_builders() const

test/test_batch_bool.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,50 @@ struct batch_bool_test
169169
}
170170
}
171171

172+
template <size_t... Is>
173+
struct pack
174+
{
175+
};
176+
177+
template <size_t... Values>
178+
void check_constructor_from_sequence(std::integral_constant<size_t, 0>, pack<Values...>) const
179+
{
180+
bool_array_type res = { bool(Values % 3)... };
181+
bool_array_type tmp;
182+
batch_bool_type b0(bool(Values % 3)...);
183+
b0.store_unaligned(tmp.data());
184+
INFO("batch_bool(values...)");
185+
CHECK_EQ(tmp, res);
186+
187+
batch_bool_type b1 { bool(Values % 3)... };
188+
b1.store_unaligned(tmp.data());
189+
INFO("batch_bool{values...}");
190+
CHECK_EQ(tmp, res);
191+
}
192+
193+
template <size_t I, size_t... Values>
194+
void check_constructor_from_sequence(std::integral_constant<size_t, I>, pack<Values...>) const
195+
{
196+
return check_constructor_from_sequence(std::integral_constant<size_t, I - 1>(), pack<Values..., I>());
197+
}
198+
172199
void test_constructors() const
173200
{
201+
batch_bool_type a;
202+
// value uninitialized, cannot test it.
203+
174204
bool_array_type res;
175205
batch_bool_type b(true);
176206
b.store_unaligned(res.data());
207+
INFO("batch_bool{value}");
177208
CHECK_EQ(res, all_true);
178209

179210
batch_bool_type c { true };
180211
c.store_unaligned(res.data());
212+
INFO("batch_bool{value}");
181213
CHECK_EQ(res, all_true);
214+
215+
check_constructor_from_sequence(std::integral_constant<size_t, size>(), pack<>());
182216
}
183217

184218
void test_load_store() const

0 commit comments

Comments
 (0)