summaryrefslogtreecommitdiff
path: root/Tests/AK
diff options
context:
space:
mode:
authorr-paiva <rui.paiva.10@hotmail.com>2021-05-10 21:49:54 +0100
committerAndreas Kling <kling@serenityos.org>2021-05-20 23:53:06 +0200
commitedcfbdf4bd9fa43b1c4164e856996e59b3a40749 (patch)
treeddf1393e26f61d6ac737df561510fa11031e1802 /Tests/AK
parent68de9008e753ad577e00da5f035b98a4d51512ec (diff)
downloadserenity-edcfbdf4bd9fa43b1c4164e856996e59b3a40749.zip
AK: Added contains_in_range to Vector
Vector::contains_in_range() allows the search of an element in a given range on a vector object. Also added testcases for the new Vector method.
Diffstat (limited to 'Tests/AK')
-rw-r--r--Tests/AK/TestVector.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/Tests/AK/TestVector.cpp b/Tests/AK/TestVector.cpp
index 0439a0605f..673838a368 100644
--- a/Tests/AK/TestVector.cpp
+++ b/Tests/AK/TestVector.cpp
@@ -399,3 +399,43 @@ TEST_CASE(should_find_index)
EXPECT_EQ(4u, v.find_first_index(0).value());
EXPECT(!v.find_first_index(42).has_value());
}
+
+TEST_CASE(should_contain_start)
+{
+ // Tests whether value is found if at the start of the range.
+ Vector<int> v { 1, 2, 3, 4, 5 };
+
+ EXPECT(v.contains_in_range(1, 0, 4));
+}
+
+TEST_CASE(should_contain_end)
+{
+ // Tests whether value is found if at the end of the range.
+ Vector<int> v { 1, 2, 3, 4, 5 };
+
+ EXPECT(v.contains_in_range(5, 0, 4));
+}
+
+TEST_CASE(should_contain_range)
+{
+ // Tests whether value is found within a range.
+ Vector<int> v { 1, 2, 3, 4, 5 };
+
+ EXPECT(v.contains_in_range(3, 0, 4));
+}
+
+TEST_CASE(should_not_contain_not_present)
+{
+ // Tests whether a value that is not present is not found, as expected.
+ Vector<int> v { 1, 2, 3, 4, 5 };
+
+ EXPECT(!v.contains_in_range(6, 0, 4));
+}
+
+TEST_CASE(should_not_contain_present_not_in_range)
+{
+ // Tests whether a value that is present, but not in range, is not found.
+ Vector<int> v { 1, 2, 3, 4, 5 };
+
+ EXPECT(!v.contains_in_range(2, 2, 4));
+}