summaryrefslogtreecommitdiff
path: root/Tests/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-11 17:16:13 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-11 17:42:31 +0200
commit88c8451973ea4e70bbe32bef617c68b018a450ed (patch)
tree544751ea1c2b361ef2b2c9f3a66fcb6fe874d1d4 /Tests/AK
parent846685fca2e613e1f77c065c6b56704c0c449900 (diff)
downloadserenity-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.txt1
-rw-r--r--Tests/AK/TestFixedArray.cpp29
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);
+}