summaryrefslogtreecommitdiff
path: root/Tests/AK/TestVector.cpp
diff options
context:
space:
mode:
authorFederico Guerinoni <guerinoni.federico@gmail.com>2022-02-23 15:59:00 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-09 17:16:28 +0100
commitb0e74a3fd30953df972c805d46f8456e84c5024c (patch)
tree1c6a0ac70fc64917a6951249c1dbcfc5313712ec /Tests/AK/TestVector.cpp
parent74650b4e328372874a0a86c8fc9716ec177f51d6 (diff)
downloadserenity-b0e74a3fd30953df972c805d46f8456e84c5024c.zip
AK: Implement reverse iterator for Vector class
Diffstat (limited to 'Tests/AK/TestVector.cpp')
-rw-r--r--Tests/AK/TestVector.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/Tests/AK/TestVector.cpp b/Tests/AK/TestVector.cpp
index 2289c24639..4cfa6da98d 100644
--- a/Tests/AK/TestVector.cpp
+++ b/Tests/AK/TestVector.cpp
@@ -533,3 +533,29 @@ TEST_CASE(reference_deletion_should_not_affect_object)
}
EXPECT_EQ(times_deleted, 1u);
}
+
+TEST_CASE(rbegin)
+{
+ Vector<int> v { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
+
+ auto const expected = v.begin() + 4;
+ auto const expected_in_reverse = v.rbegin() + 4;
+ EXPECT_EQ(*expected, *expected_in_reverse);
+}
+
+TEST_CASE(rend)
+{
+ Vector<int> v { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
+
+ const auto expected = v.end() - 5;
+ const auto expected_in_reverse = v.rend() - 5;
+ EXPECT_EQ(*expected, *expected_in_reverse);
+}
+
+TEST_CASE(reverse_loop)
+{
+ Vector<int> v { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ int index = 9;
+ for (auto rev = v.rbegin(); rev != v.rend(); ++rev)
+ EXPECT_EQ(*rev, index--);
+}