-
Notifications
You must be signed in to change notification settings - Fork 0
/
deps_test.ts
60 lines (54 loc) · 1.38 KB
/
deps_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
import { divide, last, len } from "./deps.ts";
import { assertEquals, describe, it } from "./_dev_deps.ts";
describe("len", () => {
it("should return number of items", () => {
const table: [Iterable<unknown>, number][] = [
[[], 0],
[[0], 1],
[[0, 0, 0], 3],
[{
*[Symbol.iterator]() {
yield 0;
yield 0;
},
}, 2],
[new Array(10000), 10000],
];
table.forEach(([iterable, expected]) => {
assertEquals(len(iterable), expected);
});
});
});
describe("last", () => {
it("should return last item", () => {
const table: [Iterable<unknown>, unknown][] = [
[[], undefined],
[[0], 0],
[[0, 1, 2], 2],
[{
*[Symbol.iterator]() {
yield "a";
yield "b";
},
}, "b"],
];
table.forEach(([iterable, expected]) => {
assertEquals(last(iterable), expected);
});
});
});
describe("divide", () => {
it("should return divided tuple", () => {
const table: [string, string, [string, string]][] = [
["abc", "", ["abc", ""]],
["abc", "b", ["a", "c"]],
["abcbc", "b", ["a", "cbc"]],
["abcbc", "a", ["", "bcbc"]],
["abcbc", "c", ["ab", "bc"]],
["abcbc", "d", ["abcbc", ""]],
];
table.forEach(([input, delimiter, expected]) => {
assertEquals(divide(input, delimiter), expected);
});
});
});