diff options
author | Jesse Buhagiar <jooster669@gmail.com> | 2021-05-11 21:47:48 +1000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-05-26 16:36:53 +0430 |
commit | 2b123cc59259fb6487f2e96ef89d66dd0759b7d6 (patch) | |
tree | aeb305229ae75c78d79a00fc2f474125572c5166 /Tests | |
parent | 814e35902e37d22bd56095a3e7c553337c5a628b (diff) | |
download | serenity-2b123cc59259fb6487f2e96ef89d66dd0759b7d6.zip |
AK: Implement AK::Stack
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/AK/TestStack.cpp | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index b74893f0f8..5f2b371495 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -47,6 +47,7 @@ set(AK_TEST_SOURCES TestSourceGenerator.cpp TestSourceLocation.cpp TestSpan.cpp + TestStack.cpp TestString.cpp TestStringUtils.cpp TestStringView.cpp diff --git a/Tests/AK/TestStack.cpp b/Tests/AK/TestStack.cpp new file mode 100644 index 0000000000..ddbe2765d7 --- /dev/null +++ b/Tests/AK/TestStack.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestCase.h> + +#include <AK/Stack.h> + +TEST_CASE(basic) +{ + AK::Stack<int, 3> stack; + + EXPECT(stack.is_empty() == true); + stack.push(2); + stack.push(4); + stack.push(17); + EXPECT(stack.size() == 3); + EXPECT(stack.top() == 17); + EXPECT_EQ(stack.pop(), true); + EXPECT_EQ(stack.pop(), true); + EXPECT_EQ(stack.pop(), true); + EXPECT(stack.is_empty()); +} + +TEST_CASE(complex_type) +{ + AK::Stack<String, 4> stack; + + EXPECT_EQ(stack.is_empty(), true); + EXPECT(stack.push("Well")); + EXPECT(stack.push("Hello")); + EXPECT(stack.push("Friends")); + EXPECT(stack.push(":^)")); + EXPECT_EQ(stack.top(), ":^)"); + EXPECT_EQ(stack.pop(), true); + EXPECT_EQ(stack.top(), "Friends"); + EXPECT_EQ(stack.pop(), true); + EXPECT_EQ(stack.top(), "Hello"); + EXPECT_EQ(stack.pop(), true); + EXPECT_EQ(stack.top(), "Well"); + EXPECT_EQ(stack.pop(), true); + EXPECT(stack.is_empty()); +} |