Merge pull request #12276 from ClickHouse/test-pod-array

Added a test for PaddedPODArray just in case
This commit is contained in:
alexey-milovidov 2020-07-08 14:27:16 +03:00 committed by GitHub
commit 51afbf8f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,3 +44,25 @@ TEST(Common, PODPushBackRawMany)
EXPECT_EQ(15, chars.size());
EXPECT_EQ(std::string("first0123456789"), std::string(chars.data(), chars.size()));
}
TEST(Common, PODNoOverallocation)
{
/// Check that PaddedPODArray allocates for smaller number of elements than the power of two due to padding.
/// NOTE: It's Ok to change these numbers if you will modify initial size or padding.
PaddedPODArray<char> chars;
std::vector<size_t> capacities;
size_t prev_capacity = 0;
for (size_t i = 0; i < 1000000; ++i)
{
chars.emplace_back();
if (chars.capacity() != prev_capacity)
{
prev_capacity = chars.capacity();
capacities.emplace_back(prev_capacity);
}
}
EXPECT_EQ(capacities, (std::vector<size_t>{4065, 8161, 16353, 32737, 65505, 131041, 262113, 524257, 1048545}));
}