mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user