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 pathflat.test.ts
64 lines (62 loc) · 1.64 KB
/
flat.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
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { Tests } from "@vangware/test";
import type { ReadOnlyArray } from "@vangware/types";
import { flat } from "../src/flat.js";
import { iterableToArray } from "../src/iterableToArray.js";
import { asyncIterateArray } from "./utils.js";
const array = [0, 1, 2, 3];
const arrayOfArrays = [
[0, 1],
[2, 3],
];
const arrayDeeper = [arrayOfArrays, arrayOfArrays];
export default [
{
given: "an array that already is flat",
must: "return the same array",
received: () => iterableToArray(flat(array)),
wanted: () => array,
},
{
given: "an array of arrays and a depth of 1",
must: "return a flattened array",
received: () => iterableToArray(flat(arrayOfArrays)),
wanted: () => [0, 1, 2, 3],
},
{
given: "an array arrays of arrays and a depth of 1",
must: "return an array of arrays",
received: () => iterableToArray(flat(arrayDeeper)),
wanted: () => [
[0, 1],
[2, 3],
[0, 1],
[2, 3],
],
},
{
given: "an async iterable that already is flat",
must: "return the same iterable",
received: () => iterableToArray(flat(asyncIterateArray(array))),
wanted: () => array,
},
{
given: "an async iterable of arrays and a depth of 1",
must: "return a flattened iterable",
received: () =>
iterableToArray(
flat(asyncIterateArray(arrayOfArrays.map(asyncIterateArray))),
),
wanted: () => [0, 1, 2, 3],
},
{
given: "an async iterable of arrays and a depth of 1",
must: "return an iterable of arrays",
received: () => iterableToArray(flat(asyncIterateArray(arrayDeeper))),
wanted: () => [
[0, 1],
[2, 3],
[0, 1],
[2, 3],
],
},
] satisfies Tests<ReadOnlyArray<ReadOnlyArray<number> | number>>;