Skip to content

Commit d446946

Browse files
committed
Split test file
1 parent c300258 commit d446946

File tree

11 files changed

+2556
-2429
lines changed

11 files changed

+2556
-2429
lines changed

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,22 @@ add_test(
2121
COMMAND beman.inplace_vector.ref-test
2222
)
2323

24-
# GoogleTest based tests
24+
#GoogleTest based tests
2525
include(GoogleTest)
2626

27-
add_executable(beman.inplace_vector.tests.spec)
28-
target_sources(beman.inplace_vector.tests.spec PRIVATE spec.test.cpp)
29-
target_link_libraries(
30-
beman.inplace_vector.tests.spec
31-
PRIVATE beman.inplace_vector GTest::gtest GTest::gtest_main
32-
)
27+
function(add_gtest NAME)
28+
add_executable(beman.inplace_vector.tests.${NAME})
29+
target_sources(beman.inplace_vector.tests.${NAME} PRIVATE ${NAME}.test.cpp)
30+
target_link_libraries(
31+
beman.inplace_vector.tests.${NAME}
32+
PRIVATE beman.inplace_vector GTest::gtest GTest::gtest_main
33+
)
34+
gtest_add_tests(beman.inplace_vector.tests.${NAME} "" AUTO)
35+
endfunction()
3336

34-
gtest_add_tests(beman.inplace_vector.tests.spec "" AUTO)
37+
#Tests for official specs
38+
add_gtest(container_requirements)
39+
add_gtest(triviality)
40+
add_gtest(constructors)
41+
add_gtest(size_n_data)
42+
add_gtest(erasure)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Inplace Vector Testing Suite
2+
3+
This folder contains tests for `inplace_vector` implementation.
4+
5+
The aim for the test cases are to keep the implementation in-check with its standing in the latest C++ draft.
6+
7+
You can checkout `inplace_vector`'s current state in C++ draft [here](https://eel.is/c++draft/inplace.vector).
8+
9+
## C++ Draft paragraph to test file
10+
11+
`inplace_vector`'s chapter number in the latest C++ draft is **23.3.14**.
12+
13+
### Overview (23.3.14.1)
14+
15+
[Overview](https://eel.is/c++draft/inplace.vector#overview) has 6 clauses.
16+
17+
#### 6.1 Overview
18+
19+
> An inplace_vector is a contiguous container. Its capacity is fixed and its
20+
elements are stored within the inplace_vector object itself.
21+
22+
This is not testable.
23+
24+
#### 6.2 Container Requirements
25+
26+
> An inplace_vector meets all of the requirements of a container ([container.reqmts]),
27+
> of a reversible container ([container.rev.reqmts]), of a contiguous container,
28+
> and of a sequence container, including most of the optional sequence
29+
container requirements ([sequence.reqmts]). The exceptions are the push_front,
30+
> prepend_range, pop_front, and emplace_front member functions,
31+
> which are not provided.
32+
> Descriptions are provided here only for operations on inplace_vector that
33+
> are not described in one of these tables or for operations where there is
34+
> additional semantic information.
35+
36+
See [container_requirements.test.cpp](container_requirements.test.cpp).
37+
38+
#### 6.3 Constexpr Iterator
39+
40+
> For any N, `inplace_vector<T, N>​::​iterator` and
41+
> `inplace_vector<T, N>​::​const_iterator` meet the constexpr iterator
42+
> requirements.
43+
44+
Not tested for now.
45+
46+
#### 6.4 Constexpr member functions
47+
48+
> For any $N>0$, if T is not trivially copyable or
49+
> `is_trivially_default_constructible_v<T>` is false,
50+
> then no `inplace_vector<T, N>` member functions are usable in
51+
> constant expressions.
52+
53+
Not tested for now.
54+
55+
#### 6.5 Bad alloc requirement
56+
57+
> Any member function of `inplace_vector<T, N>` that would cause the size to
58+
> exceed N throws an exception of type bad_alloc.
59+
60+
These are tested with individual functions.
61+
62+
#### 6.6 Triviality
63+
64+
Let IV denote a specialization of `inplace_vector<T, N>`.
65+
> If N is zero, then IV is trivially copyable and empty,
66+
> and std​::​is_trivially_default_constructible_v<IV> is true.
67+
> (Sub-clauses omitted)
68+
69+
See [triviality.test.cpp](triviality.test.cpp)
70+
71+
### Constructors (23.3.14.2)
72+
73+
See [constructors.test.cpp](constructors.test.cpp)
74+
75+
### Size and capacity (23.3.14.3)
76+
77+
See [size_n_data.test.cpp](size_n_data.test.cpp)
78+
79+
### Data (23.3.14.4)
80+
81+
See [size_n_data.test.cpp](size_n_data.test.cpp)
82+
83+
### Modifiers (23.3.14.5)
84+
85+
See [modifiers.test.cpp](modifiers.test.cpp)
86+
87+
### Erasure (23.3.14.6)
88+
89+
See [erasure.test.cpp](erasure.test.cpp)
90+
91+
## Other tests
92+
93+
- [ref_impl.test.cpp](ref_impl.test.cpp):
94+
Is the test suite imported from reference implementation in
95+
[P0843R14](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0843r14.html).
96+
Originally included [here on godbolt](https://godbolt.org/z/5P78aG5xE).
97+
- [inplace_vector.test.cpp](inplace_vector.test.cpp):
98+
A minimal test suite by @Hels15 for their implementation.
99+
100+
## Known Issues/ Missed Tests
101+
102+
- Constexpr related functionalities.
103+
- Emplacement minimal copy/ construction.
104+
- Exception safety on mutation.
105+
106+
## Special Thanks
107+
108+
Special thanks to Jan Babst (@jbab) for his contribution at setting up the
109+
Google Test infrastructure.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <gtest/gtest.h>
2+
#include <numeric>
3+
4+
#include "gtest_setup.hpp"
5+
6+
namespace {
7+
// 23.3.14.2 Constructors [inplace.vector.cons]
8+
9+
template <typename Param> class Constructors : public IVBasicTest<Param> {};
10+
TYPED_TEST_SUITE(Constructors, IVAllTypes);
11+
12+
TYPED_TEST(Constructors, SizedDefault) {
13+
// constexpr explicit inplace_vector(size_type n);
14+
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
15+
// Effects: Constructs an inplace_vector with n default-inserted elements.
16+
// Complexity : Linear in n.
17+
18+
using IV = TestFixture::IV;
19+
using T = TestFixture::T;
20+
21+
IV zero(0);
22+
EXPECT_EQ(zero, IV{});
23+
24+
EXPECT_THROW(IV(IV::capacity() + 1), beman::bad_alloc);
25+
26+
constexpr auto mid_size = std::midpoint(0ul, IV::capacity());
27+
IV mid(mid_size);
28+
EXPECT_EQ(mid.size(), mid_size);
29+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
30+
std::is_same_v<T, NonTrivial>) {
31+
32+
IV mid_correct;
33+
for (auto i = 0ul; i < mid_size; ++i)
34+
mid_correct.emplace_back();
35+
36+
EXPECT_EQ(mid, mid_correct);
37+
}
38+
39+
IV full(IV::capacity());
40+
EXPECT_EQ(full.size(), IV::capacity());
41+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
42+
std::is_same_v<T, NonTrivial>) {
43+
44+
IV full_correct;
45+
for (auto i = 0ul; i < full.size(); ++i)
46+
full_correct.emplace_back();
47+
48+
EXPECT_EQ(full, full_correct);
49+
}
50+
}
51+
52+
TYPED_TEST(Constructors, SizedValue) {
53+
// constexpr inplace_vector(size_type n, const T& value);
54+
// Preconditions: T is Cpp17CopyInsertable into inplace_vector.
55+
// Effects: Constructs an inplace_vector with n copies of value.
56+
// Complexity: Linear in n.
57+
// TODO
58+
GTEST_SKIP();
59+
}
60+
61+
TYPED_TEST(Constructors, CopyIter) {
62+
// template<class InputIterator>
63+
// constexpr inplace_vector(InputIterator first, InputIterator last);
64+
// Effects: Constructs an inplace_vector equal to the range [first, last).
65+
// Complexity: Linear in distance(first, last).
66+
// TODO
67+
GTEST_SKIP();
68+
}
69+
70+
TYPED_TEST(Constructors, CopyRanges) {
71+
// template<container-compatible-range<T> R>
72+
// constexpr inplace_vector(from_range_t, R&& rg);
73+
// Effects: Constructs an inplace_vector with the elements of the range rg.
74+
// Complexity: Linear in ranges::distance(rg).
75+
// TODO
76+
GTEST_SKIP();
77+
}
78+
}; // namespace

0 commit comments

Comments
 (0)