MCPcopy Create free account
hub / github.com/catboost/catboost / TestHMapConstructorsAndAssignments

Method TestHMapConstructorsAndAssignments

util/generic/hash_ut.cpp:177–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177void THashTest::TestHMapConstructorsAndAssignments() {
178 using container = THashMap<TString, int>;
179
180 container c1;
181 c1["one"] = 1;
182 c1["two"] = 2;
183
184 container c2(c1);
185
186 UNIT_ASSERT_VALUES_EQUAL(2, c1.size());
187 UNIT_ASSERT_VALUES_EQUAL(2, c2.size());
188 UNIT_ASSERT_VALUES_EQUAL(1, c1.at("one")); /* Note: fails under MSVC since it does not support implicit generation of move constructors. */
189 UNIT_ASSERT_VALUES_EQUAL(2, c2.at("two"));
190
191 container c3(std::move(c1));
192
193 UNIT_ASSERT_VALUES_EQUAL(0, c1.size());
194 UNIT_ASSERT_VALUES_EQUAL(2, c3.size());
195 UNIT_ASSERT_VALUES_EQUAL(1, c3.at("one"));
196
197 c2["three"] = 3;
198 c3 = c2;
199
200 UNIT_ASSERT_VALUES_EQUAL(3, c2.size());
201 UNIT_ASSERT_VALUES_EQUAL(3, c3.size());
202 UNIT_ASSERT_VALUES_EQUAL(3, c3.at("three"));
203
204 c2["four"] = 4;
205 c3 = std::move(c2);
206
207 UNIT_ASSERT_VALUES_EQUAL(0, c2.size());
208 UNIT_ASSERT_VALUES_EQUAL(4, c3.size());
209 UNIT_ASSERT_VALUES_EQUAL(4, c3.at("four"));
210
211 const container c4{
212 {"one", 1},
213 {"two", 2},
214 {"three", 3},
215 {"four", 4},
216 };
217
218 UNIT_ASSERT_VALUES_EQUAL(4, c4.size());
219 UNIT_ASSERT_VALUES_EQUAL(1, c4.at("one"));
220 UNIT_ASSERT_VALUES_EQUAL(2, c4.at("two"));
221 UNIT_ASSERT_VALUES_EQUAL(3, c4.at("three"));
222 UNIT_ASSERT_VALUES_EQUAL(4, c4.at("four"));
223
224 // non-existent values must be zero-initialized
225 UNIT_ASSERT_VALUES_EQUAL(c1["nonexistent"], 0);
226}
227
228void THashTest::TestHMap1() {
229 using maptype = THashMap<char, TString, THash<char>, TEqualTo<char>>;

Callers

nothing calls this directly

Calls 3

moveFunction · 0.50
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected