-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlist.test.ts
48 lines (41 loc) · 829 Bytes
/
list.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
import { assertEquals, assertThrows } from "../../deps.ts";
import {
arrayToList,
arrayToListFor,
arrayToListReduce,
nth,
prepend,
} from "./list.ts";
const rest = {
value: 1,
rest: {
value: 2,
rest: {
value: 3,
rest: null,
},
},
};
Deno.test("[arrayToList]", () => {
assertEquals(arrayToList([1, 2, 3]), rest);
});
Deno.test("[arrayToListFor]", () => {
assertEquals(arrayToListFor([1, 2, 3]), rest);
});
Deno.test("[arrayToListReduce]", () => {
assertEquals(arrayToListReduce([1, 2, 3]), rest);
});
Deno.test("[nth]", () => {
const nth3 = nth(rest, 2);
assertEquals(nth3, 3);
assertThrows(
() => {
nth(rest, 5);
},
RangeError,
"Index out of range",
);
});
Deno.test("[prepend]", () => {
assertEquals(prepend(4, rest), { value: 4, rest });
});