mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
// 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);
|
|
});
|