Skip to content

Commit

Permalink
Enable all iterator tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jun 8, 2024
1 parent 0ddaaa5 commit a68a69c
Showing 1 changed file with 23 additions and 57 deletions.
80 changes: 23 additions & 57 deletions test/primitives/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,6 @@ class iterator_
const base::manager manager_;
};

BOOST_AUTO_TEST_CASE(iterator_test)
{
using link = linkage<1>;
using key = data_array<2>;
constexpr size_t value = 1;
using record_iterate = iterator_<link, key, value>;
static_assert(link::terminal == 0xff);

constexpr link head{ 0 };
constexpr key key2{ 0x1a, 0x2a };
data_chunk data
{
0x01, 0x1a, 0x2a, 0xee,
0x02, 0x1a, 0x2a, 0xee,
0xff, 0xcc, 0xcc, 0xee
};
test::chunk_storage file{ data };
record_iterate iterator1{ file, head, key2 };

// First record is 0x00.
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x00u);

// Next record is 0x01 (data[0]->data[4]).
BOOST_REQUIRE_EQUAL(iterator1.get_next_(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// Set self/link to record 0x01.
BOOST_REQUIRE(iterator1.advance());
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// Next record is 0x02 (data[4]->data[8]).
BOOST_REQUIRE_EQUAL(iterator1.get_next_(), 0x02u);
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// Advance returns false (no match) and self becomes terminal.
BOOST_REQUIRE(!iterator1.advance());
BOOST_REQUIRE(!iterator1.is_match_());
BOOST_REQUIRE(iterator1.self().is_terminal());
BOOST_REQUIRE(!iterator1.advance());
BOOST_REQUIRE(!iterator1.is_match_());
BOOST_REQUIRE(iterator1.self().is_terminal());
}

#if defined(DISABLED)

BOOST_AUTO_TEST_CASE(iterator__get_next__empty__terminal)
{
using link = linkage<4>;
Expand Down Expand Up @@ -185,9 +138,11 @@ BOOST_AUTO_TEST_CASE(iterator__next__self__expected)
{
using link = linkage<1>;
using key = data_array<2>;
using record_iterate = iterator_<link, key, 1>;
constexpr size_t value = 1;
using record_iterate = iterator_<link, key, value>;
static_assert(link::terminal == 0xff);

constexpr auto start = 0;
constexpr link head{ 0 };
constexpr key key2{ 0x1a, 0x2a };
data_chunk data
{
Expand All @@ -196,19 +151,32 @@ BOOST_AUTO_TEST_CASE(iterator__next__self__expected)
0xff, 0xcc, 0xcc, 0xee
};
test::chunk_storage file{ data };
record_iterate iterator1{ file, start, key2 };
record_iterate iterator1{ file, head, key2 };

// First link is zero, matched.
// First record is 0x00.
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x00u);

// Sets self/link to 0x01 (data[4]), matched.
// Next record is 0x01 (data[0]->data[4]).
BOOST_REQUIRE_EQUAL(iterator1.get_next_(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// Set self/link to record 0x01.
BOOST_REQUIRE(iterator1.advance());
BOOST_REQUIRE(!iterator1.self().is_terminal());
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// No more matches.
// Next record is 0x02 (data[4]->data[8]).
BOOST_REQUIRE_EQUAL(iterator1.get_next_(), 0x02u);
BOOST_REQUIRE_EQUAL(iterator1.self(), 0x01u);
BOOST_REQUIRE(iterator1.is_match_());

// Advance returns false (no match) and self becomes terminal.
BOOST_REQUIRE(!iterator1.advance());
BOOST_REQUIRE(!iterator1.is_match_());
BOOST_REQUIRE(iterator1.self().is_terminal());
BOOST_REQUIRE(!iterator1.advance());
BOOST_REQUIRE_EQUAL(iterator1.self(), link::terminal);
BOOST_REQUIRE(!iterator1.is_match_());
BOOST_REQUIRE(iterator1.self().is_terminal());
}

BOOST_AUTO_TEST_CASE(iterator__next__true__non_terminal)
Expand All @@ -235,6 +203,4 @@ BOOST_AUTO_TEST_CASE(iterator__next__true__non_terminal)
BOOST_REQUIRE(iterator.self().is_terminal());
}

#endif // DISABLED

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a68a69c

Please sign in to comment.