From 5ce7c67e44a4c06a58235caf0029afac67491e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 23 Feb 2022 11:30:20 +0100 Subject: Tests: Test DisjointChunks with FixedArray --- Tests/AK/TestDisjointChunks.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'Tests/AK/TestDisjointChunks.cpp') diff --git a/Tests/AK/TestDisjointChunks.cpp b/Tests/AK/TestDisjointChunks.cpp index 94f052bf9e..8c0e854a69 100644 --- a/Tests/AK/TestDisjointChunks.cpp +++ b/Tests/AK/TestDisjointChunks.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -54,6 +55,48 @@ TEST_CASE(basic) EXPECT_EQ(new_chunks[2], 5u); } +TEST_CASE(fixed_array) +{ + DisjointChunks> chunks; + EXPECT(chunks.is_empty()); + chunks.append({}); + EXPECT(chunks.is_empty()); + chunks.append(MUST(FixedArray::try_create({ 0, 1 }))); + EXPECT(!chunks.is_empty()); + chunks.append({}); + chunks.append(MUST(FixedArray::try_create(3))); + chunks.last_chunk()[0] = 2; + chunks.last_chunk()[1] = 3; + chunks.last_chunk()[2] = 4; + chunks.append({}); + chunks.append(MUST(FixedArray::try_create(1))); + chunks.last_chunk()[0] = 5; + + for (size_t i = 0; i < 6u; ++i) + EXPECT_EQ(chunks.at(i), i); + + auto it = chunks.begin(); + for (size_t i = 0; i < 6u; ++i, ++it) + EXPECT_EQ(*it, i); + + EXPECT_EQ(it, chunks.end()); + + DisjointChunks> new_chunks; + new_chunks.extend(move(chunks)); + EXPECT_EQ(new_chunks.size(), 6u); + + auto cut_off_slice = new_chunks.release_slice(2, 3); + EXPECT_EQ(new_chunks.size(), 3u); + EXPECT_EQ(cut_off_slice.size(), 3u); + + EXPECT_EQ(cut_off_slice[0], 2u); + EXPECT_EQ(cut_off_slice[1], 3u); + EXPECT_EQ(cut_off_slice[2], 4u); + + EXPECT_EQ(new_chunks[0], 0u); + EXPECT_EQ(new_chunks[1], 1u); +} + TEST_CASE(spans) { DisjointChunks chunks; -- cgit v1.2.3