-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pairwise_test.ts
25 lines (22 loc) · 960 Bytes
/
pairwise_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { pairwise } from "./pairwise.ts";
await test("pairwise with non empty iterable", () => {
const result = pairwise([1, 2, 3, 4, 5]);
const expected = [[1, 2], [2, 3], [3, 4], [4, 5]];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, number]>>>(true);
});
await test("pairwise with single value iterable", () => {
const result = pairwise([1]);
const expected: number[][] = [];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, number]>>>(true);
});
await test("pairwise with empty iterable", () => {
const result = pairwise([] as number[]);
const expected: number[][] = [];
assertEquals(Array.from(result), expected);
assertType<IsExact<typeof result, Iterable<[number, number]>>>(true);
});