| 226 | } |
| 227 | |
| 228 | void THashTest::TestHMap1() { |
| 229 | using maptype = THashMap<char, TString, THash<char>, TEqualTo<char>>; |
| 230 | maptype m; |
| 231 | // Store mappings between roman numerals and decimals. |
| 232 | m['l'] = "50"; |
| 233 | m['x'] = "20"; // Deliberate mistake. |
| 234 | m['v'] = "5"; |
| 235 | m['i'] = "1"; |
| 236 | UNIT_ASSERT(!strcmp(m['x'].c_str(), "20")); |
| 237 | m['x'] = "10"; // Correct mistake. |
| 238 | UNIT_ASSERT(!strcmp(m['x'].c_str(), "10")); |
| 239 | |
| 240 | UNIT_ASSERT(!m.contains('z')); |
| 241 | UNIT_ASSERT(!strcmp(m['z'].c_str(), "")); |
| 242 | UNIT_ASSERT(m.contains('z')); |
| 243 | |
| 244 | UNIT_ASSERT(m.count('z') == 1); |
| 245 | auto p = m.insert(std::pair<const char, TString>('c', TString("100"))); |
| 246 | |
| 247 | UNIT_ASSERT(p.second); |
| 248 | |
| 249 | p = m.insert(std::pair<const char, TString>('c', TString("100"))); |
| 250 | UNIT_ASSERT(!p.second); |
| 251 | |
| 252 | // Some iterators compare check, really compile time checks |
| 253 | maptype::iterator ite(m.begin()); |
| 254 | maptype::const_iterator cite(m.begin()); |
| 255 | cite = m.begin(); |
| 256 | maptype const& cm = m; |
| 257 | cite = cm.begin(); |
| 258 | |
| 259 | UNIT_ASSERT((maptype::const_iterator)ite == cite); |
| 260 | UNIT_ASSERT(!((maptype::const_iterator)ite != cite)); |
| 261 | UNIT_ASSERT(cite == (maptype::const_iterator)ite); |
| 262 | UNIT_ASSERT(!(cite != (maptype::const_iterator)ite)); |
| 263 | } |
| 264 | |
| 265 | void THashTest::TestHMapEqualityOperator() { |
| 266 | using container = THashMap<TString, int>; |