-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
some_test.ts
37 lines (35 loc) · 1.1 KB
/
some_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
import { test } from "@cross/test";
import { assertEquals } from "@std/assert";
import { assertType, type IsExact } from "@std/testing/types";
import { some } from "./some.ts";
await test("some returns true if some elements satisfy the function", () => {
const values: number[] = [];
const indices: number[] = [];
const result = some([1, 2, 3, 4, 5], (v, index) => {
values.push(v);
indices.push(index);
return v > 2;
});
const expected = true;
assertEquals(result, expected);
assertEquals(values, [1, 2, 3]);
assertEquals(indices, [0, 1, 2]);
assertType<IsExact<typeof result, boolean>>(true);
});
await test(
"some returns false if no elements satisfy the function",
() => {
const values: number[] = [];
const indices: number[] = [];
const result = some([1, 2, 3, 4, 5], (v, index) => {
values.push(v);
indices.push(index);
return v > 5;
});
const expected = false;
assertEquals(result, expected);
assertEquals(values, [1, 2, 3, 4, 5]);
assertEquals(indices, [0, 1, 2, 3, 4]);
assertType<IsExact<typeof result, boolean>>(true);
},
);