2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-08-24 07:07:32 +00:00
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2021-08-24 07:07:32 +00:00
|
|
|
import { withoutAll } from "./without_all.ts";
|
|
|
|
|
|
|
|
function withoutAllTest<I>(
|
|
|
|
input: Array<I>,
|
|
|
|
excluded: Array<I>,
|
|
|
|
expected: Array<I>,
|
|
|
|
message?: string,
|
|
|
|
) {
|
|
|
|
const actual = withoutAll(input, excluded);
|
|
|
|
assertEquals(actual, expected, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() handles no mutation",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
|
|
|
const array = [1, 2, 3, 4];
|
|
|
|
withoutAll(array, [2, 3]);
|
|
|
|
assertEquals(array, [1, 2, 3, 4]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() handles empty input",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
|
|
|
withoutAllTest([], [], []);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() handles no matches",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
|
|
|
withoutAllTest([1, 2, 3, 4], [0, 7, 9], [1, 2, 3, 4]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() handles single match",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
|
|
|
withoutAllTest([1, 2, 3, 4], [1], [2, 3, 4]);
|
|
|
|
withoutAllTest([1, 2, 3, 2], [2], [1, 3]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() handles multiple matches",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
|
|
|
withoutAllTest([1, 2, 3, 4, 6, 3], [1, 2], [3, 4, 6, 3]);
|
|
|
|
withoutAllTest([7, 2, 9, 8, 7, 6, 5, 7], [7, 9], [2, 8, 6, 5]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 09:48:02 +00:00
|
|
|
name: "withoutAll() leaves duplicate elements",
|
2021-08-24 07:07:32 +00:00
|
|
|
fn() {
|
2021-11-11 09:21:06 +00:00
|
|
|
withoutAllTest(
|
|
|
|
Array.from({ length: 110 }, () => 3),
|
|
|
|
[1],
|
|
|
|
Array.from({ length: 110 }, () => 3),
|
|
|
|
);
|
2021-08-24 07:07:32 +00:00
|
|
|
},
|
|
|
|
});
|