This repository was archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtake.test.ts
51 lines (49 loc) · 1.6 KB
/
take.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { Tests } from "@vangware/test";
import type { ReadOnlyArray } from "@vangware/types";
import { iterableToArray } from "../src/iterableToArray.js";
import { take } from "../src/take.js";
import { asyncIterateArray } from "./utils.js";
const take2 = take(2);
const takeNone = take(0);
const takeAll = take(Infinity);
export default [
{
given: "an array of numbers and a take 2 function",
must: "return array with only the first 2 elements",
received: () => iterableToArray(take2([0, 1, 2, 3, 4])),
wanted: () => [0, 1],
},
{
given: "an array of numbers and a take 0 function",
must: "return an empty array",
received: () => iterableToArray(takeNone([0, 1, 2, 3, 4])),
wanted: () => [],
},
{
given: "an array of numbers and a take all function",
must: "return the whole array",
received: () => iterableToArray(takeAll([0, 1, 2, 3, 4])),
wanted: () => [0, 1, 2, 3, 4],
},
{
given: "an async iterable of numbers and a take 2 function",
must: "return async iterable with only the first 2 elements",
received: () =>
iterableToArray(take2(asyncIterateArray([0, 1, 2, 3, 4]))),
wanted: () => [0, 1],
},
{
given: "an async iterable of numbers and a take 0 function",
must: "return an empty async iterable",
received: () =>
iterableToArray(takeNone(asyncIterateArray([0, 1, 2, 3, 4]))),
wanted: () => [],
},
{
given: "an async iterable of numbers and a take all function",
must: "return the whole async iterable",
received: () =>
iterableToArray(takeAll(asyncIterateArray([0, 1, 2, 3, 4]))),
wanted: () => [0, 1, 2, 3, 4],
},
] satisfies Tests<ReadOnlyArray<number>>;