MCPcopy Create free account
hub / github.com/HelenOS/helenos / test_emplace_insert

Method test_emplace_insert

uspace/lib/cpp/src/__bits/test/unordered_map.cpp:135–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133 }
134
135 void unordered_map_test::test_emplace_insert()
136 {
137 std::unordered_map<int, int> map1{};
138
139 auto res1 = map1.emplace(1, 2);
140 test_eq("first emplace succession", res1.second, true);
141 test_eq("first emplace equivalence pt1", res1.first->first, 1);
142 test_eq("first emplace equivalence pt2", res1.first->second, 2);
143
144 auto res2 = map1.emplace(1, 3);
145 test_eq("second emplace failure", res2.second, false);
146 test_eq("second emplace equivalence pt1", res2.first->first, 1);
147 test_eq("second emplace equivalence pt2", res2.first->second, 2);
148
149 auto res3 = map1.emplace_hint(map1.begin(), 2, 4);
150 test_eq("first emplace_hint succession", (res3 != map1.end()), true);
151 test_eq("first emplace_hint equivalence pt1", res3->first, 2);
152 test_eq("first emplace_hint equivalence pt2", res3->second, 4);
153
154 auto res4 = map1.emplace_hint(map1.begin(), 2, 5);
155 test_eq("second emplace_hint failure", (res4 != map1.end()), true);
156 test_eq("second emplace_hint equivalence pt1", res4->first, 2);
157 test_eq("second emplace_hint equivalence pt2", res4->second, 4);
158
159 std::unordered_map<int, std::string> map2{};
160 auto res5 = map2.insert(std::pair<const int, const char*>{5, "A"});
161 test_eq("conversion insert succession", res5.second, true);
162 test_eq("conversion insert equivalence pt1", res5.first->first, 5);
163 test_eq("conversion insert equivalence pt2", res5.first->second, std::string{"A"});
164
165 auto res6 = map2.insert(std::pair<const int, std::string>{6, "B"});
166 test_eq("first insert succession", res6.second, true);
167 test_eq("first insert equivalence pt1", res6.first->first, 6);
168 test_eq("first insert equivalence pt2", res6.first->second, std::string{"B"});
169
170 auto res7 = map2.insert(std::pair<const int, std::string>{6, "C"});
171 test_eq("second insert failure", res7.second, false);
172 test_eq("second insert equivalence pt1", res7.first->first, 6);
173 test_eq("second insert equivalence pt2", res7.first->second, std::string{"B"});
174
175 auto res8 = map2.insert_or_assign(6, std::string{"D"});
176 test_eq("insert_or_*assign* result", res8.second, false);
177 test_eq("insert_or_*assign* equivalence pt1", res8.first->first, 6);
178 test_eq("insert_or_*assign* equivalence pt2", res8.first->second, std::string{"D"});
179
180 auto res9 = map2.insert_or_assign(7, std::string{"E"});
181 test_eq("*insert*_or_assign result", res9.second, true);
182 test_eq("*insert*_or_assign equivalence pt1", res9.first->first, 7);
183 test_eq("*insert*_or_assign equivalence pt2", res9.first->second, std::string{"E"});
184
185 map2.erase(map2.find(7));
186 test_eq("erase", map2.find(7), map2.end());
187
188 auto res10 = map2.erase(6);
189 test_eq("erase by key pt1", res10, 1U);
190 auto res11 = map2.erase(6);
191 test_eq("erase by key pt2", res11, 0U);
192

Callers

nothing calls this directly

Calls 11

emplaceMethod · 0.45
emplace_hintMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
insert_or_assignMethod · 0.45
eraseMethod · 0.45
findMethod · 0.45
countMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected