diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-11 17:16:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 17:42:31 +0200 |
commit | 88c8451973ea4e70bbe32bef617c68b018a450ed (patch) | |
tree | 544751ea1c2b361ef2b2c9f3a66fcb6fe874d1d4 /Tests/AK | |
parent | 846685fca2e613e1f77c065c6b56704c0c449900 (diff) | |
download | serenity-88c8451973ea4e70bbe32bef617c68b018a450ed.zip |
AK: Bring back FixedArray<T>
Let's bring this class back, but without the confusing resize() API.
A FixedArray<T> is simply a fixed-size array of T.
The size is provided at run-time, unlike Array<T> where the size is
provided at compile-time.
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/AK/TestFixedArray.cpp | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index 346165afd0..8459a55706 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -21,6 +21,7 @@ set(AK_TEST_SOURCES TestEndian.cpp TestEnumBits.cpp TestFind.cpp + TestFixedArray.cpp TestFormat.cpp TestGenericLexer.cpp TestHashFunctions.cpp diff --git a/Tests/AK/TestFixedArray.cpp b/Tests/AK/TestFixedArray.cpp new file mode 100644 index 0000000000..6b33818c62 --- /dev/null +++ b/Tests/AK/TestFixedArray.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestSuite.h> + +#include <AK/FixedArray.h> +#include <AK/String.h> + +TEST_CASE(construct) +{ + EXPECT(FixedArray<int>().size() == 0); +} + +TEST_CASE(ints) +{ + FixedArray<int> ints(3); + ints[0] = 0; + ints[1] = 1; + ints[2] = 2; + EXPECT_EQ(ints[0], 0); + EXPECT_EQ(ints[1], 1); + EXPECT_EQ(ints[2], 2); + + ints.clear(); + EXPECT_EQ(ints.size(), 0u); +} |