6 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
12 #include <gtest/gtest.h>
20 return std::string(buf);
25 EXPECT_FALSE(value.empty());
26 const int num = atoi(value.c_str());
75 static const int POOL_BLOCKS = 4;
78 typedef Multiset<std::string> MultisetType;
79 std::unique_ptr<MultisetType> mset(
new MultisetType(pool));
84 mset->removeFirst(
"foo");
86 ASSERT_FALSE(mset->getByIndex(0));
87 ASSERT_FALSE(mset->getByIndex(1));
88 ASSERT_FALSE(mset->getByIndex(10000));
91 ASSERT_EQ(
"1", *mset->emplace(
"1"));
92 ASSERT_EQ(
"2", *mset->emplace(
"2"));
94 ASSERT_EQ(2, mset->getSize());
97 StringConcatenationOperator op;
98 mset->forEach<StringConcatenationOperator&>(op);
99 ASSERT_EQ(2, op.accumulator.size());
103 ASSERT_EQ(
"3", *mset->emplace(
"3"));
106 ASSERT_EQ(
"4", *mset->emplace(
"4"));
108 ASSERT_EQ(4, mset->getSize());
110 ASSERT_FALSE(mset->getByIndex(100));
111 ASSERT_FALSE(mset->getByIndex(4));
121 StringConcatenationOperator op;
122 mset->forEach<StringConcatenationOperator&>(op);
123 std::cout <<
"Accumulator: " << op.accumulator << std::endl;
124 ASSERT_EQ(4, op.accumulator.size());
128 mset->removeFirst(
"1");
129 mset->removeFirst(
"foo");
130 mset->removeFirst(
"2");
133 unsigned max_value_integer = 0;
134 for (
int i = 0; i < 100; i++)
136 const std::string value =
toString(i);
137 std::string* res = mset->emplace(value);
145 ASSERT_EQ(value, *res);
147 max_value_integer = unsigned(i);
149 std::cout <<
"Max value: " << max_value_integer << std::endl;
153 ASSERT_FALSE(mset->emplace(
"nonexistent"));
159 for (
unsigned kv_int = 0; kv_int <= max_value_integer; kv_int++)
164 ASSERT_FALSE(kv_int & 1);
168 ASSERT_TRUE(kv_int & 1);
174 StringConcatenationOperator op;
175 mset->forEach<StringConcatenationOperator&>(op);
176 std::cout <<
"Accumulator before clearing: " << op.accumulator << std::endl;
180 StringConcatenationOperator op;
181 mset->forEach<StringConcatenationOperator&>(op);
182 std::cout <<
"Accumulator after clearing: " << op.accumulator << std::endl;
183 ASSERT_TRUE(op.accumulator.empty());
196 static const int POOL_BLOCKS = 3;
199 typedef Multiset<int> MultisetType;
200 std::unique_ptr<MultisetType> mset(
new MultisetType(pool));
203 mset->removeFirst(8);
205 ASSERT_EQ(0, mset->getSize());
206 ASSERT_FALSE(mset->getByIndex(0));
209 ASSERT_EQ(1, *mset->emplace(1));
210 ASSERT_EQ(1, mset->getSize());
211 ASSERT_EQ(2, *mset->emplace(2));
212 ASSERT_EQ(2, mset->getSize());
213 ASSERT_EQ(3, *mset->emplace(3));
214 ASSERT_EQ(4, *mset->emplace(4));
215 ASSERT_EQ(4, mset->getSize());
221 ASSERT_EQ(1 + 2 + 3 + 4, summation_operator.
accumulator);
236 static const int POOL_BLOCKS = 3;
239 typedef Multiset<NoncopyableWithCounter> MultisetType;
240 std::unique_ptr<MultisetType> mset(
new MultisetType(pool));
243 ASSERT_EQ(0, mset->emplace()->value);
245 ASSERT_EQ(123, mset->emplace(123)->value);
247 ASSERT_EQ(-456, mset->emplace(-456)->value);
249 ASSERT_EQ(456, mset->emplace(456)->value);
251 ASSERT_EQ(-789, mset->emplace(-789)->value);