-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfind_test.ts
More file actions
26 lines (24 loc) · 816 Bytes
/
find_test.ts
File metadata and controls
26 lines (24 loc) · 816 Bytes
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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { find } from "./find.ts";
await test("find found", () => {
const values: number[] = [];
const indices: number[] = [];
const result = find([1, 2, 3, 4, 5], (v, index) => {
values.push(v);
indices.push(index);
return v % 2 === 0;
});
const expected = 2;
assertEquals(result, expected);
assertEquals(values, [1, 2]);
assertEquals(indices, [0, 1]);
assertType<IsExact<typeof result, number | undefined>>(true);
});
await test("find not found", () => {
const result = find([1, 2, 3, 4, 5], () => false);
const expected = undefined;
assertEquals(result, expected);
assertType<IsExact<typeof result, number | undefined>>(true);
});