mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
test(collections): add tests for filterInPlace()
util (#6089)
This commit is contained in:
parent
a6a9b86fec
commit
0312678936
31
collections/_utils_test.ts
Normal file
31
collections/_utils_test.ts
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
import { filterInPlace } from "./_utils.ts";
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
|
||||
Deno.test("filterInPlace() filters out elements not matching predicate", () => {
|
||||
const array = [1, 2, 3, 4, 5];
|
||||
const result = filterInPlace(array, (el) => el > 2 && el < 5);
|
||||
assertEquals(result, [3, 4]);
|
||||
assert(array === result);
|
||||
});
|
||||
|
||||
Deno.test("filterInPlace() filters out all elements when none match predicate", () => {
|
||||
const array = [1, 2, 3, 4, 5];
|
||||
const result = filterInPlace(array, (el) => el > 5);
|
||||
assertEquals(result, []);
|
||||
assert(array === result);
|
||||
});
|
||||
|
||||
Deno.test("filterInPlace() filters out no elements when all match predicate", () => {
|
||||
const array = [1, 2, 3, 4, 5];
|
||||
const result = filterInPlace(array, (el) => el > 0);
|
||||
assertEquals(result, [1, 2, 3, 4, 5]);
|
||||
assert(array === result);
|
||||
});
|
||||
|
||||
Deno.test("filterInPlace() filters out no elements when array is empty", () => {
|
||||
const array: number[] = [];
|
||||
const result = filterInPlace(array, (el) => el > 0);
|
||||
assertEquals(result, []);
|
||||
assert(array === result);
|
||||
});
|
Loading…
Reference in New Issue
Block a user