mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:38:10 +00:00
AK: Implement reverse iterator for Vector class
This commit is contained in:
parent
74650b4e32
commit
b0e74a3fd3
2 changed files with 30 additions and 0 deletions
|
@ -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--);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue