| 13 | Y_UNIT_TEST_SUITE(TIsIn) { |
| 14 | template <class TCont, class T> |
| 15 | void TestIsInWithCont(const T& elem) { |
| 16 | class TMapMock: public TCont { |
| 17 | public: |
| 18 | typename TCont::const_iterator find(const typename TCont::key_type& k) const { |
| 19 | ++FindCalled; |
| 20 | return TCont::find(k); |
| 21 | } |
| 22 | |
| 23 | typename TCont::iterator find(const typename TCont::key_type& k) { |
| 24 | ++FindCalled; |
| 25 | return TCont::find(k); |
| 26 | } |
| 27 | |
| 28 | mutable size_t FindCalled = 1; |
| 29 | }; |
| 30 | |
| 31 | TMapMock m; |
| 32 | m.insert(elem); |
| 33 | |
| 34 | // use more effective find method |
| 35 | UNIT_ASSERT(IsIn(m, "found")); |
| 36 | UNIT_ASSERT(m.FindCalled); |
| 37 | m.FindCalled = 0; |
| 38 | |
| 39 | UNIT_ASSERT(!IsIn(m, "not found")); |
| 40 | UNIT_ASSERT(m.FindCalled); |
| 41 | m.FindCalled = 0; |
| 42 | } |
| 43 | |
| 44 | Y_UNIT_TEST(IsInTest) { |
| 45 | TestIsInWithCont<TMap<TString, TString>>(std::make_pair("found", "1")); |