-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
drop_test.ts
26 lines (23 loc) · 961 Bytes
/
drop_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { test } from "@cross/test";
import { assertEquals, assertThrows } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { drop } from "./drop.ts";
await test("drop with positive limit", () => {
const result = drop([0, 1, 2, 3, 4], 2);
const expected = [2, 3, 4];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});
await test("drop with 0 limit", () => {
const result = drop([0, 1, 2, 3, 4], 0);
const expected = [0, 1, 2, 3, 4];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<number>>>(true);
});
await test("drop throws RangeError", () => {
assertThrows(() => drop([], NaN), RangeError);
assertThrows(() => drop([], Infinity), RangeError);
assertThrows(() => drop([], -Infinity), RangeError);
assertThrows(() => drop([], -1), RangeError);
assertThrows(() => drop([], 1.1), RangeError);
});