Skip to content

Commit f2b483c

Browse files
committed
add tests for empty vec
1 parent 6eb2bc7 commit f2b483c

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

tests/beman/inplace_vector/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ See [constexpr.test.cpp](constexpr.test.cpp),
5454
note that this test suite only ensure functions are usable in a constexpr
5555
environment.
5656
The validity of those functions are tested in the main test suite.
57+
This test also doesn't exhaustivly test constexpr functions' behavior
58+
when exception throwing is expected.
5759

5860
#### 6.5 Bad alloc requirement
5961

@@ -102,7 +104,6 @@ See [erasure.test.cpp](erasure.test.cpp)
102104

103105
## Known Issues/ Missed Tests
104106

105-
- Constexpr related functionalities.
106107
- Emplacement minimal copy/ construction.
107108
- Exception safety on mutation.
108109

tests/beman/inplace_vector/constexpr.test.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ template <typename IV> constexpr void test_iterator_access() {
122122
(void)v.rend();
123123
(void)v.cbegin();
124124
(void)v.cend();
125+
(void)v.crbegin();
126+
(void)v.crend();
125127
}
126128
}
127129
TEST(test_iterator_access);
@@ -254,6 +256,89 @@ template <typename IV> constexpr void test_erase() {
254256
}
255257
TEST(test_erase)
256258

259+
struct Complex {
260+
int val = 0;
261+
262+
constexpr bool operator==(const Complex &other) const {
263+
return val == other.val;
264+
}
265+
constexpr auto operator<=>(const Complex &other) const {
266+
return val <=> other.val;
267+
}
268+
};
269+
static_assert(!std::is_trivially_default_constructible_v<Complex>);
270+
271+
#define TEST_EMPTY(NAME) \
272+
static_assert(std::invoke([]() { \
273+
NAME<Complex>(); \
274+
return true; \
275+
}), \
276+
"##NAME");
277+
278+
template <typename T> constexpr void speical_test_empty() {
279+
static_assert(!std::is_trivially_default_constructible_v<T>);
280+
using IV = beman::inplace_vector<T, 0>;
281+
282+
std::array<T, 10> arr;
283+
arr.fill(T{50});
284+
285+
{
286+
IV v;
287+
}
288+
{
289+
IV v(0, T{50});
290+
}
291+
{
292+
IV a, b;
293+
a = b;
294+
a = IV();
295+
}
296+
{
297+
IV v;
298+
v.assign(0, T{50});
299+
}
300+
{
301+
IV v;
302+
(void)v.begin();
303+
(void)v.end();
304+
(void)v.rbegin();
305+
(void)v.rend();
306+
(void)v.cbegin();
307+
(void)v.cend();
308+
(void)v.crbegin();
309+
(void)v.crend();
310+
}
311+
{
312+
IV v;
313+
(void)v.empty();
314+
(void)v.size();
315+
(void)v.max_size();
316+
(void)v.capacity();
317+
v.resize(0);
318+
v.resize(0, T{40});
319+
v.reserve(0);
320+
v.shrink_to_fit();
321+
}
322+
{
323+
IV v;
324+
v.try_emplace_back(50);
325+
v.try_push_back(T(50));
326+
v.try_push_back(arr[0]);
327+
// v.try_append_range(arr);
328+
v.clear();
329+
}
330+
{
331+
IV a, b;
332+
a.swap(b);
333+
}
334+
{
335+
IV a, b;
336+
(void)(a == b);
337+
(void)(a <=> b);
338+
}
339+
}
340+
TEST_EMPTY(speical_test_empty);
341+
257342
int main() {
258343
// compile means passing
259344
}

0 commit comments

Comments
 (0)