Commit 321addf0 by Vitaly Goldshteyn Committed by Copybara-Service

Test that rehash(0) reduces capacity to minimum.

PiperOrigin-RevId: 615380243
Change-Id: I5400b40a6bc5ac52ece5d4fa6da7df9e4ff50855
parent 03856129
...@@ -885,12 +885,17 @@ TYPED_TEST_P(SmallTableResizeTest, ResizeReduceSmallTables) { ...@@ -885,12 +885,17 @@ TYPED_TEST_P(SmallTableResizeTest, ResizeReduceSmallTables) {
for (size_t source_size = 0; source_size < 32; ++source_size) { for (size_t source_size = 0; source_size < 32; ++source_size) {
for (size_t target_size = 0; target_size <= source_size; ++target_size) { for (size_t target_size = 0; target_size <= source_size; ++target_size) {
TypeParam t; TypeParam t;
t.reserve(source_size);
size_t inserted_count = std::min<size_t>(source_size, 5); size_t inserted_count = std::min<size_t>(source_size, 5);
for (size_t i = 0; i < inserted_count; ++i) { for (size_t i = 0; i < inserted_count; ++i) {
t.insert(static_cast<int>(i)); t.insert(static_cast<int>(i));
} }
const size_t minimum_capacity = t.capacity();
t.reserve(source_size);
t.rehash(target_size); t.rehash(target_size);
if (target_size == 0) {
EXPECT_EQ(t.capacity(), minimum_capacity)
<< "rehash(0) must resize to the minimum capacity";
}
for (size_t i = 0; i < inserted_count; ++i) { for (size_t i = 0; i < inserted_count; ++i) {
EXPECT_TRUE(t.find(static_cast<int>(i)) != t.end()); EXPECT_TRUE(t.find(static_cast<int>(i)) != t.end());
EXPECT_EQ(*t.find(static_cast<int>(i)), static_cast<int>(i)); EXPECT_EQ(*t.find(static_cast<int>(i)), static_cast<int>(i));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment