#include #include #include #include #include using namespace NFlatHash; namespace { constexpr size_t INIT_SIZE = 128; template void SmokingTest(Container& cont) { using value_type = typename Container::value_type; using iterator = TIterator; using size_type = typename Container::size_type; iterator f(&cont), l(&cont, cont.Size()); UNIT_ASSERT_EQUAL(f, l); UNIT_ASSERT_EQUAL((size_type)std::distance(f, l), cont.Taken()); TVector> toAdd{ { 0, (int)RandomNumber(INIT_SIZE) }, { 1 + RandomNumber(INIT_SIZE - 2), (int)RandomNumber(INIT_SIZE) }, { INIT_SIZE - 1, (int)RandomNumber(INIT_SIZE) } }; for (const auto& p : toAdd) { UNIT_ASSERT(cont.IsEmpty(p.first)); cont.InitNode(p.first, p.second); } UNIT_ASSERT_EQUAL(cont.Size(), INIT_SIZE); f = iterator{ &cont }; l = iterator{ &cont, INIT_SIZE }; UNIT_ASSERT_UNEQUAL(f, l); UNIT_ASSERT_EQUAL((size_type)std::distance(f, l), cont.Taken()); TVector added(f, l); UNIT_ASSERT(::Equal(toAdd.begin(), toAdd.end(), added.begin(), [](const auto& p, auto v) { return p.second == v; })); } template void ConstTest(Container& cont) { using value_type = typename Container::value_type; using iterator = TIterator; using const_iterator = TIterator; iterator it{ &cont, INIT_SIZE / 2 }; const_iterator cit1{ it }; const_iterator cit2{ &cont, INIT_SIZE / 2 }; UNIT_ASSERT_EQUAL(cit1, cit2); static_assert(std::is_same::value); static_assert(std::is_same::value); } } Y_UNIT_TEST_SUITE(TIteratorTest) { Y_UNIT_TEST(SmokingTest) { { TFlatContainer cont(INIT_SIZE); SmokingTest(cont); } { TDenseContainer> cont(INIT_SIZE); SmokingTest(cont); } } Y_UNIT_TEST(ConstTest) { { TFlatContainer cont(INIT_SIZE); ConstTest(cont); } { TDenseContainer> cont(INIT_SIZE); ConstTest(cont); } } }