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

Method test_emplace_insert

uspace/lib/cpp/src/__bits/test/unordered_set.cpp:106–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104 }
105
106 void unordered_set_test::test_emplace_insert()
107 {
108 std::unordered_set<int> set1{};
109
110 auto res1 = set1.emplace(1);
111 test_eq("first emplace succession", res1.second, true);
112 test_eq("first emplace equivalence", *res1.first, 1);
113
114 auto res2 = set1.emplace(1);
115 test_eq("second emplace failure", res2.second, false);
116 test_eq("second emplace equivalence", *res2.first, 1);
117
118 auto res3 = set1.emplace_hint(set1.begin(), 2);
119 test_eq("first emplace_hint succession", (res3 != set1.end()), true);
120 test_eq("first emplace_hint equivalence", *res3, 2);
121
122 auto res4 = set1.emplace_hint(set1.begin(), 2);
123 test_eq("second emplace_hint failure", (res4 != set1.end()), true);
124 test_eq("second emplace_hint equivalence", *res4, 2);
125
126 std::unordered_set<std::string> set2{};
127 auto res5 = set2.insert("A");
128 test_eq("conversion insert succession", res5.second, true);
129 test_eq("conversion insert equivalence", *res5.first, std::string{"A"});
130
131 auto res6 = set2.insert(std::string{"B"});
132 test_eq("first insert succession", res6.second, true);
133 test_eq("first insert equivalence", *res6.first, std::string{"B"});
134
135 auto res7 = set2.insert(std::string{"B"});
136 test_eq("second insert failure", res7.second, false);
137 test_eq("second insert equivalence", *res7.first, std::string{"B"});
138
139 auto res10 = set1.erase(set1.find(2));
140 test_eq("erase", set1.find(2), set1.end());
141 test_eq("highest erased", res10, set1.end());
142
143 set2.insert(std::string{"G"});
144 set2.insert(std::string{"H"});
145 set2.insert(std::string{"K"});
146 auto res11 = set2.erase(std::string{"G"});
147 test_eq("erase by key pt1", res11, 1U);
148 auto res12 = set2.erase(std::string{"M"});
149 test_eq("erase by key pt2", res12, 0U);
150
151 std::unordered_set<int> set3{};
152 set3.insert(1);
153 auto res13 = set3.erase(1);
154 test_eq("erase only element by key pt1", res13, 1U);
155 test_eq("erase only element by key pt2", set3.empty(), true);
156
157 set3.insert(3);
158 auto res14 = set3.erase(set3.begin());
159 test_eq("erase only element by iterator pt1", res14, set3.end());
160 test_eq("erase only element by iterator pt2", set3.empty(), true);
161
162 set2.clear();
163 test_eq("clear", set2.empty(), true);

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected