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

Method test_emplace_insert

uspace/lib/cpp/src/__bits/test/map.cpp:153–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 }
152
153 void map_test::test_emplace_insert()
154 {
155 std::map<int, int> map1{};
156
157 auto res1 = map1.emplace(1, 2);
158 test_eq("first emplace succession", res1.second, true);
159 test_eq("first emplace equivalence pt1", res1.first->first, 1);
160 test_eq("first emplace equivalence pt2", res1.first->second, 2);
161
162 auto res2 = map1.emplace(1, 3);
163 test_eq("second emplace failure", res2.second, false);
164 test_eq("second emplace equivalence pt1", res2.first->first, 1);
165 test_eq("second emplace equivalence pt2", res2.first->second, 2);
166
167 auto res3 = map1.emplace_hint(map1.begin(), 2, 4);
168 test_eq("first emplace_hint succession", (res3 != map1.end()), true);
169 test_eq("first emplace_hint equivalence pt1", res3->first, 2);
170 test_eq("first emplace_hint equivalence pt2", res3->second, 4);
171
172 auto res4 = map1.emplace_hint(map1.begin(), 2, 5);
173 test_eq("second emplace_hint failure", (res4 != map1.end()), true);
174 test_eq("second emplace_hint equivalence pt1", res4->first, 2);
175 test_eq("second emplace_hint equivalence pt2", res4->second, 4);
176
177 std::map<int, std::string> map2{};
178 auto res5 = map2.insert(std::pair<const int, const char*>{5, "A"});
179 test_eq("conversion insert succession", res5.second, true);
180 test_eq("conversion insert equivalence pt1", res5.first->first, 5);
181 test_eq("conversion insert equivalence pt2", res5.first->second, std::string{"A"});
182
183 auto res6 = map2.insert(std::pair<const int, std::string>{6, "B"});
184 test_eq("first insert succession", res6.second, true);
185 test_eq("first insert equivalence pt1", res6.first->first, 6);
186 test_eq("first insert equivalence pt2", res6.first->second, std::string{"B"});
187
188 auto res7 = map2.insert(std::pair<const int, std::string>{6, "C"});
189 test_eq("second insert failure", res7.second, false);
190 test_eq("second insert equivalence pt1", res7.first->first, 6);
191 test_eq("second insert equivalence pt2", res7.first->second, std::string{"B"});
192
193 auto res8 = map2.insert_or_assign(6, std::string{"D"});
194 test_eq("insert_or_*assign* result", res8.second, false);
195 test_eq("insert_or_*assign* equivalence pt1", res8.first->first, 6);
196 test_eq("insert_or_*assign* equivalence pt2", res8.first->second, std::string{"D"});
197
198 auto res9 = map2.insert_or_assign(7, std::string{"E"});
199 test_eq("*insert*_or_assign result", res9.second, true);
200 test_eq("*insert*_or_assign equivalence pt1", res9.first->first, 7);
201 test_eq("*insert*_or_assign equivalence pt2", res9.first->second, std::string{"E"});
202
203 auto res10 = map2.erase(map2.find(7));
204 test_eq("erase", map2.find(7), map2.end());
205 test_eq("highest erased", res10, map2.end());
206
207 auto res11 = map2.erase(6);
208 test_eq("erase by key pt1", res11, 1U);
209 auto res12 = map2.erase(6);
210 test_eq("erase by key pt2", res12, 0U);

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
emptyMethod · 0.45
clearMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected