Skip to content

Commit

Permalink
Split test file
Browse files Browse the repository at this point in the history
  • Loading branch information
wusatosi committed Jan 17, 2025
1 parent c300258 commit d446946
Show file tree
Hide file tree
Showing 11 changed files with 2,556 additions and 2,429 deletions.
24 changes: 16 additions & 8 deletions tests/beman/inplace_vector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ add_test(
COMMAND beman.inplace_vector.ref-test
)

# GoogleTest based tests
#GoogleTest based tests
include(GoogleTest)

add_executable(beman.inplace_vector.tests.spec)
target_sources(beman.inplace_vector.tests.spec PRIVATE spec.test.cpp)
target_link_libraries(
beman.inplace_vector.tests.spec
PRIVATE beman.inplace_vector GTest::gtest GTest::gtest_main
)
function(add_gtest NAME)
add_executable(beman.inplace_vector.tests.${NAME})
target_sources(beman.inplace_vector.tests.${NAME} PRIVATE ${NAME}.test.cpp)
target_link_libraries(
beman.inplace_vector.tests.${NAME}
PRIVATE beman.inplace_vector GTest::gtest GTest::gtest_main
)
gtest_add_tests(beman.inplace_vector.tests.${NAME} "" AUTO)
endfunction()

gtest_add_tests(beman.inplace_vector.tests.spec "" AUTO)
#Tests for official specs
add_gtest(container_requirements)
add_gtest(triviality)
add_gtest(constructors)
add_gtest(size_n_data)
add_gtest(erasure)
109 changes: 109 additions & 0 deletions tests/beman/inplace_vector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Inplace Vector Testing Suite

This folder contains tests for `inplace_vector` implementation.

The aim for the test cases are to keep the implementation in-check with its standing in the latest C++ draft.

You can checkout `inplace_vector`'s current state in C++ draft [here](https://eel.is/c++draft/inplace.vector).

## C++ Draft paragraph to test file

`inplace_vector`'s chapter number in the latest C++ draft is **23.3.14**.

### Overview (23.3.14.1)

[Overview](https://eel.is/c++draft/inplace.vector#overview) has 6 clauses.

#### 6.1 Overview

> An inplace_vector is a contiguous container. Its capacity is fixed and its
elements are stored within the inplace_vector object itself.

This is not testable.

#### 6.2 Container Requirements

> An inplace_vector meets all of the requirements of a container ([container.reqmts]),
> of a reversible container ([container.rev.reqmts]), of a contiguous container,
> and of a sequence container, including most of the optional sequence
container requirements ([sequence.reqmts]). The exceptions are the push_front,
> prepend_range, pop_front, and emplace_front member functions,
> which are not provided.
> Descriptions are provided here only for operations on inplace_vector that
> are not described in one of these tables or for operations where there is
> additional semantic information.
See [container_requirements.test.cpp](container_requirements.test.cpp).

#### 6.3 Constexpr Iterator

> For any N, `inplace_vector<T, N>​::​iterator` and
> `inplace_vector<T, N>​::​const_iterator` meet the constexpr iterator
> requirements.
Not tested for now.

#### 6.4 Constexpr member functions

> For any $N>0$, if T is not trivially copyable or
> `is_trivially_default_constructible_v<T>` is false,
> then no `inplace_vector<T, N>` member functions are usable in
> constant expressions.
Not tested for now.

#### 6.5 Bad alloc requirement

> Any member function of `inplace_vector<T, N>` that would cause the size to
> exceed N throws an exception of type bad_alloc.
These are tested with individual functions.

#### 6.6 Triviality

Let IV denote a specialization of `inplace_vector<T, N>`.
> If N is zero, then IV is trivially copyable and empty,
> and std​::​is_trivially_default_constructible_v<IV> is true.
> (Sub-clauses omitted)
See [triviality.test.cpp](triviality.test.cpp)

### Constructors (23.3.14.2)

See [constructors.test.cpp](constructors.test.cpp)

### Size and capacity (23.3.14.3)

See [size_n_data.test.cpp](size_n_data.test.cpp)

### Data (23.3.14.4)

See [size_n_data.test.cpp](size_n_data.test.cpp)

### Modifiers (23.3.14.5)

See [modifiers.test.cpp](modifiers.test.cpp)

### Erasure (23.3.14.6)

See [erasure.test.cpp](erasure.test.cpp)

## Other tests

- [ref_impl.test.cpp](ref_impl.test.cpp):
Is the test suite imported from reference implementation in
[P0843R14](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0843r14.html).
Originally included [here on godbolt](https://godbolt.org/z/5P78aG5xE).
- [inplace_vector.test.cpp](inplace_vector.test.cpp):
A minimal test suite by @Hels15 for their implementation.

## Known Issues/ Missed Tests

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

## Special Thanks

Special thanks to Jan Babst (@jbab) for his contribution at setting up the
Google Test infrastructure.
78 changes: 78 additions & 0 deletions tests/beman/inplace_vector/constructors.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <gtest/gtest.h>
#include <numeric>

#include "gtest_setup.hpp"

namespace {
// 23.3.14.2 Constructors [inplace.vector.cons]

template <typename Param> class Constructors : public IVBasicTest<Param> {};
TYPED_TEST_SUITE(Constructors, IVAllTypes);

TYPED_TEST(Constructors, SizedDefault) {
// constexpr explicit inplace_vector(size_type n);
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
// Effects: Constructs an inplace_vector with n default-inserted elements.
// Complexity : Linear in n.

using IV = TestFixture::IV;
using T = TestFixture::T;

IV zero(0);
EXPECT_EQ(zero, IV{});

EXPECT_THROW(IV(IV::capacity() + 1), beman::bad_alloc);

constexpr auto mid_size = std::midpoint(0ul, IV::capacity());
IV mid(mid_size);
EXPECT_EQ(mid.size(), mid_size);
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
std::is_same_v<T, NonTrivial>) {

IV mid_correct;
for (auto i = 0ul; i < mid_size; ++i)
mid_correct.emplace_back();

EXPECT_EQ(mid, mid_correct);
}

IV full(IV::capacity());
EXPECT_EQ(full.size(), IV::capacity());
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
std::is_same_v<T, NonTrivial>) {

IV full_correct;
for (auto i = 0ul; i < full.size(); ++i)
full_correct.emplace_back();

EXPECT_EQ(full, full_correct);
}
}

TYPED_TEST(Constructors, SizedValue) {
// constexpr inplace_vector(size_type n, const T& value);
// Preconditions: T is Cpp17CopyInsertable into inplace_vector.
// Effects: Constructs an inplace_vector with n copies of value.
// Complexity: Linear in n.
// TODO
GTEST_SKIP();
}

TYPED_TEST(Constructors, CopyIter) {
// template<class InputIterator>
// constexpr inplace_vector(InputIterator first, InputIterator last);
// Effects: Constructs an inplace_vector equal to the range [first, last).
// Complexity: Linear in distance(first, last).
// TODO
GTEST_SKIP();
}

TYPED_TEST(Constructors, CopyRanges) {
// template<container-compatible-range<T> R>
// constexpr inplace_vector(from_range_t, R&& rg);
// Effects: Constructs an inplace_vector with the elements of the range rg.
// Complexity: Linear in ranges::distance(rg).
// TODO
GTEST_SKIP();
}
}; // namespace
Loading

0 comments on commit d446946

Please sign in to comment.