Skip to content

Commit 1c3b6fb

Browse files
committed
Add missing resize tests
1 parent 55b7cd6 commit 1c3b6fb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/beman/inplace_vector/size_n_data.test.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ TYPED_TEST(SizeNCapacity, ResizeDown) {
4343
EXPECT_EQ(device, IV{});
4444
}
4545

46+
TYPED_TEST(SizeNCapacity, ResizeDownWValue) {
47+
// constexpr void resize(size_type sz, const T& value);
48+
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
49+
// Effects: If sz < size(), erases the last size() - sz elements from the
50+
// sequence. Otherwise, appends sz - size() default-inserted elements to the
51+
// sequence. Remarks: If an exception is thrown, there are no effects on
52+
// *this.
53+
54+
using IV = TestFixture::IV;
55+
using T = TestFixture::T;
56+
57+
auto device = this->unique();
58+
59+
auto mid_size = std::midpoint(0ul, device.size());
60+
device.resize(mid_size, T{});
61+
EXPECT_EQ(device, IV(device.begin(), device.begin() + mid_size));
62+
63+
device.resize(0, T{});
64+
EXPECT_EQ(device, IV{});
65+
}
66+
4667
TYPED_TEST(SizeNCapacity, ResizeUp) {
4768
// constexpr void resize(size_type sz);
4869
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
@@ -90,6 +111,52 @@ TYPED_TEST(SizeNCapacity, ResizeUp) {
90111
EXPECT_EQ(device, before_resize);
91112
}
92113

114+
TYPED_TEST(SizeNCapacity, ResizeUpWValue) {
115+
// constexpr void resize(size_type sz, const T& value);
116+
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
117+
// Effects: If sz < size(), erases the last size() - sz elements from the
118+
// sequence. Otherwise, appends sz - size() default-inserted elements to the
119+
// sequence. Remarks: If an exception is thrown, there are no effects on
120+
// *this.
121+
122+
using IV = TestFixture::IV;
123+
using T = TestFixture::T;
124+
125+
IV device;
126+
127+
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1, T{}), std::bad_alloc);
128+
EXPECT_EQ(device, IV{});
129+
130+
if (device.capacity() == 0)
131+
return;
132+
133+
// Trying to pollute device[0]
134+
device.push_back(T{255});
135+
device.pop_back();
136+
EXPECT_TRUE(device.empty());
137+
138+
device.resize(1, T{0});
139+
EXPECT_EQ(device.size(), 1);
140+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
141+
std::is_same_v<T, NonTrivial>)
142+
EXPECT_EQ(device, IV{T{0}});
143+
144+
T front{341};
145+
device[0] = front;
146+
device.resize(device.capacity(), front);
147+
EXPECT_EQ(device[0], front);
148+
149+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
150+
std::is_same_v<T, NonTrivial>) {
151+
IV expected(device.capacity(), T{341});
152+
EXPECT_EQ(device, expected);
153+
}
154+
155+
IV before_resize(device);
156+
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1, T{}), std::bad_alloc);
157+
EXPECT_EQ(device, before_resize);
158+
}
159+
93160
// 23.3.14.4 Data [inplace.vector.data]
94161

95162
template <typename Param> class Data : public IVBasicTest<Param> {};

0 commit comments

Comments
 (0)