Skip to content

Commit

Permalink
add tests for empty vec
Browse files Browse the repository at this point in the history
  • Loading branch information
wusatosi committed Jan 31, 2025
1 parent ab60b87 commit b2515b7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/beman/inplace_vector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ See [constexpr.test.cpp](constexpr.test.cpp),
note that this test suite only ensure functions are usable in a constexpr
environment.
The validity of those functions are tested in the main test suite.
This test also doesn't exhaustivly test constexpr functions' behavior
when exception throwing is expected.

#### 6.5 Bad alloc requirement

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

## Known Issues/ Missed Tests

- Constexpr related functionalities.
- Emplacement minimal copy/ construction.
- Exception safety on mutation.

Expand Down
85 changes: 85 additions & 0 deletions tests/beman/inplace_vector/constexpr.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ template <typename IV> constexpr void test_iterator_access() {
(void)v.rend();
(void)v.cbegin();
(void)v.cend();
(void)v.crbegin();
(void)v.crend();
}
}
TEST(test_iterator_access);
Expand Down Expand Up @@ -254,6 +256,89 @@ template <typename IV> constexpr void test_erase() {
}
TEST(test_erase)

struct Complex {
int val = 0;

constexpr bool operator==(const Complex &other) const {
return val == other.val;
}
constexpr auto operator<=>(const Complex &other) const {
return val <=> other.val;
}
};
static_assert(!std::is_trivially_default_constructible_v<Complex>);

#define TEST_EMPTY(NAME) \
static_assert(std::invoke([]() { \
NAME<Complex>(); \
return true; \
}), \
"##NAME");

template <typename T> constexpr void speical_test_empty() {
static_assert(!std::is_trivially_default_constructible_v<T>);
using IV = beman::inplace_vector<T, 0>;

std::array<T, 10> arr;
arr.fill(T{50});

{
IV v;
}
{
IV v(0, T{50});
}
{
IV a, b;
a = b;
a = IV();
}
{
IV v;
v.assign(0, T{50});
}
{
IV v;
(void)v.begin();
(void)v.end();
(void)v.rbegin();
(void)v.rend();
(void)v.cbegin();
(void)v.cend();
(void)v.crbegin();
(void)v.crend();
}
{
IV v;
(void)v.empty();
(void)v.size();
(void)v.max_size();
(void)v.capacity();
v.resize(0);
v.resize(0, T{40});
v.reserve(0);
v.shrink_to_fit();
}
{
IV v;
v.try_emplace_back(50);
v.try_push_back(T(50));
v.try_push_back(arr[0]);
// v.try_append_range(arr);
v.clear();
}
{
IV a, b;
a.swap(b);
}
{
IV a, b;
(void)(a == b);
(void)(a <=> b);
}
}
TEST_EMPTY(speical_test_empty);

int main() {
// compile means passing
}

0 comments on commit b2515b7

Please sign in to comment.