summaryrefslogtreecommitdiff
path: root/Tests/AK/TestDisjointChunks.cpp
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-02-23 11:30:20 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-02-27 00:11:14 +0330
commit5ce7c67e44a4c06a58235caf0029afac67491e85 (patch)
tree4894d73978a2ebf70dad2b7b299551899856fb30 /Tests/AK/TestDisjointChunks.cpp
parent7e18e6e37bb2593e9e3e6b6bb2976528d29a5286 (diff)
downloadserenity-5ce7c67e44a4c06a58235caf0029afac67491e85.zip
Tests: Test DisjointChunks with FixedArray
Diffstat (limited to 'Tests/AK/TestDisjointChunks.cpp')
-rw-r--r--Tests/AK/TestDisjointChunks.cpp43
1 files changed, 43 insertions, 0 deletions
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 <LibTest/TestCase.h>
#include <AK/DisjointChunks.h>
+#include <AK/FixedArray.h>
#include <AK/String.h>
#include <AK/Vector.h>
@@ -54,6 +55,48 @@ TEST_CASE(basic)
EXPECT_EQ(new_chunks[2], 5u);
}
+TEST_CASE(fixed_array)
+{
+ DisjointChunks<size_t, FixedArray<size_t>> chunks;
+ EXPECT(chunks.is_empty());
+ chunks.append({});
+ EXPECT(chunks.is_empty());
+ chunks.append(MUST(FixedArray<size_t>::try_create({ 0, 1 })));
+ EXPECT(!chunks.is_empty());
+ chunks.append({});
+ chunks.append(MUST(FixedArray<size_t>::try_create(3)));
+ chunks.last_chunk()[0] = 2;
+ chunks.last_chunk()[1] = 3;
+ chunks.last_chunk()[2] = 4;
+ chunks.append({});
+ chunks.append(MUST(FixedArray<size_t>::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<size_t, FixedArray<size_t>> 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<size_t> chunks;