2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-09-01 07:01:36 +00:00
|
|
|
import { dropLastWhile } from "./drop_last_while.ts";
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2021-09-01 07:01:36 +00:00
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() handles num array", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const values = [20, 33, 44];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(values, (i) => i > 30);
|
|
|
|
|
|
|
|
assertEquals(actual, [20]);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() handles no mutation", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const array = [1, 2, 3, 4, 5, 6];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(array, (i) => i > 4);
|
|
|
|
|
|
|
|
assertEquals(actual, [1, 2, 3, 4]);
|
|
|
|
assertEquals(array, [1, 2, 3, 4, 5, 6]);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() handles negatives", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const array = [-1, -2, -3, -4, -5, -6];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(array, (i) => i < -4);
|
|
|
|
|
|
|
|
assertEquals(actual, [-1, -2, -3, -4]);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() handles empty input returns empty array", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const array: number[] = [];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(array, (i) => i > 4);
|
|
|
|
|
|
|
|
assertEquals(actual, []);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() returns same array when the last element doesn't get dropped", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const array = [40, 30, 20];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(array, (i) => i > 40);
|
|
|
|
|
|
|
|
assertEquals(actual, [40, 30, 20]);
|
|
|
|
});
|
|
|
|
|
2023-12-20 09:48:02 +00:00
|
|
|
Deno.test("dropLastWhile() returns empty array when all elements get dropped", () => {
|
2021-09-01 07:01:36 +00:00
|
|
|
const array = [20, 30, 20];
|
|
|
|
|
|
|
|
const actual = dropLastWhile(array, (i) => i < 40);
|
|
|
|
|
|
|
|
assertEquals(actual, []);
|
|
|
|
});
|