mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-17 03:42:48 +00:00
35 lines
1.2 KiB
C++
35 lines
1.2 KiB
C++
|
#include <gtest/gtest.h>
|
||
|
|
||
|
#include <Common/PODArray.h>
|
||
|
|
||
|
using namespace DB;
|
||
|
|
||
|
TEST(Common, PODArray_Insert)
|
||
|
{
|
||
|
std::string str = "test_string_abacaba";
|
||
|
PODArray<char> chars;
|
||
|
chars.insert(chars.end(), str.begin(), str.end());
|
||
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
||
|
|
||
|
std::string insert_in_the_middle = "insert_in_the_middle";
|
||
|
auto pos = str.size() / 2;
|
||
|
str.insert(str.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
|
||
|
chars.insert(chars.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
|
||
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
||
|
|
||
|
std::string insert_with_resize;
|
||
|
insert_with_resize.reserve(chars.capacity() * 2);
|
||
|
char curChar = 'a';
|
||
|
while (insert_with_resize.size() < insert_with_resize.capacity())
|
||
|
{
|
||
|
insert_with_resize += curChar;
|
||
|
if (curChar == 'z')
|
||
|
curChar = 'a';
|
||
|
else
|
||
|
++curChar;
|
||
|
}
|
||
|
str.insert(str.begin(), insert_with_resize.begin(), insert_with_resize.end());
|
||
|
chars.insert(chars.begin(), insert_with_resize.begin(), insert_with_resize.end());
|
||
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
||
|
}
|