-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
zip_test.ts
36 lines (32 loc) · 1.37 KB
/
zip_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { zip } from "./zip.ts";
await test("zip with two iterables", () => {
const result = zip([1, 2, 3], ["a", "b", "c"]);
const expected = [[1, "a"], [2, "b"], [3, "c"]];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, string]>>>(true);
});
await test("zip with two in-balanced iterables", () => {
const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"]);
const expected = [[1, "a"], [2, "b"], [3, "c"]];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, string]>>>(true);
});
await test("zip with three iterables", () => {
const result = zip([1, 2, 3], ["a", "b", "c"], [true, false, true]);
const expected = [[1, "a", true], [2, "b", false], [3, "c", true]];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, string, boolean]>>>(
true,
);
});
await test("zip with three in-balanced iterables", () => {
const result = zip([1, 2, 3, 4, 5], ["a", "b", "c"], [true, false, true]);
const expected = [[1, "a", true], [2, "b", false], [3, "c", true]];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, string, boolean]>>>(
true,
);
});