mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-20 09:21:55 +00:00
AK: Add Array::contains_slow() and ::first_index_of(), with tests :^)
This commit is contained in:
parent
955528055c
commit
892470a912
Notes:
sideshowbarker
2024-07-17 02:59:43 +09:00
Author: https://github.com/AtkinsSJ
Commit: 892470a912
Pull-request: https://github.com/SerenityOS/serenity/pull/18441
Reviewed-by: https://github.com/linusg
Reviewed-by: https://github.com/nico
Reviewed-by: https://github.com/trflynn89
2 changed files with 33 additions and 0 deletions
|
@ -28,3 +28,21 @@ TEST_CASE(compile_time_iterable)
|
|||
constexpr Array<int, 8> array = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
static_assert(constexpr_sum(array) == 28);
|
||||
}
|
||||
|
||||
TEST_CASE(contains_slow)
|
||||
{
|
||||
constexpr Array<int, 8> array = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
EXPECT(array.contains_slow(0));
|
||||
EXPECT(array.contains_slow(4));
|
||||
EXPECT(array.contains_slow(7));
|
||||
EXPECT(!array.contains_slow(42));
|
||||
}
|
||||
|
||||
TEST_CASE(first_index_of)
|
||||
{
|
||||
constexpr Array<int, 8> array = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
EXPECT(array.first_index_of(0) == 0u);
|
||||
EXPECT(array.first_index_of(4) == 4u);
|
||||
EXPECT(array.first_index_of(7) == 7u);
|
||||
EXPECT(!array.first_index_of(42).has_value());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue