mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 05:25:13 +00:00
Tests: Test DisjointChunks with FixedArray
This commit is contained in:
parent
7e18e6e37b
commit
5ce7c67e44
Notes:
sideshowbarker
2024-07-17 18:11:33 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/5ce7c67e44 Pull-request: https://github.com/SerenityOS/serenity/pull/12733
1 changed files with 43 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue