1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

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.
This commit is contained in:
r-paiva 2021-05-10 21:49:54 +01:00 committed by Andreas Kling
parent 68de9008e7
commit edcfbdf4bd
2 changed files with 53 additions and 0 deletions

View file

@ -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));
}