| 11 | struct TTestMap: std::map<int, TString>, TMapOps<TTestMap> {}; |
| 12 | |
| 13 | Y_UNIT_TEST(TestDerivedClass) { |
| 14 | TTestMap a; |
| 15 | |
| 16 | a[42] = "cat"; |
| 17 | UNIT_ASSERT(a.FindPtr(42)); |
| 18 | UNIT_ASSERT_EQUAL(*a.FindPtr(42), "cat"); |
| 19 | UNIT_ASSERT_EQUAL(a.FindPtr(0), nullptr); |
| 20 | |
| 21 | // test mutation |
| 22 | if (TString* p = a.FindPtr(42)) { |
| 23 | *p = "dog"; |
| 24 | } |
| 25 | UNIT_ASSERT(a.FindPtr(42)); |
| 26 | UNIT_ASSERT_EQUAL(*a.FindPtr(42), "dog"); |
| 27 | |
| 28 | // test const-overloaded functions too |
| 29 | const TTestMap& b = a; |
| 30 | UNIT_ASSERT(b.FindPtr(42) && *b.FindPtr(42) == "dog"); |
| 31 | UNIT_ASSERT_EQUAL(b.FindPtr(0), nullptr); |
| 32 | |
| 33 | UNIT_ASSERT_STRINGS_EQUAL(b.Value(42, "cat"), "dog"); |
| 34 | UNIT_ASSERT_STRINGS_EQUAL(b.Value(0, "alien"), "alien"); |
| 35 | } |
| 36 | |
| 37 | Y_UNIT_TEST(TestTemplateFind) { |
| 38 | THashMap<TString, int> m; |