use slice assign and add List.*using_test functions (#967)

* std/collections: use slice assignment
* std/collections: add List.remove_using_test and List.retain_using_test
This commit is contained in:
Pierre Curto
2023-09-01 12:16:15 +02:00
committed by GitHub
parent 70b9e811bd
commit e56313a204
2 changed files with 77 additions and 8 deletions

View File

@@ -78,6 +78,23 @@ fn void! remove_if()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! remove_using_test()
{
IntList test;
usz removed;
test.add_array({ 1, 11, 2, 10, 20 });
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
assert(removed == 3);
assert(test.array_view() == int[]{1, 2});
test.clear();
test.add_array({ 1, 11, 2, 10, 20 });
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
assert(removed == 2);
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_if()
{
IntList test;
@@ -95,6 +112,23 @@ fn void! retain_if()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_using_test()
{
IntList test;
usz removed;
test.add_array({ 1, 11, 2, 10, 20 });
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
assert(removed == 3);
assert(test.array_view() == int[]{1, 2});
test.clear();
test.add_array({ 1, 11, 2, 10, 20 });
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
assert(removed == 2);
assert(test.array_view() == int[]{11, 10, 20});
}
module list_test;
fn bool filter(int* i)