forked from denoland/deno_std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
partition_test.ts
75 lines (67 loc) · 1.5 KB
/
partition_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";
import { partition } from "./partition.ts";
function partitionTest<I>(
input: [Array<I>, (element: I) => boolean],
expected: [Array<I>, Array<I>],
message?: string,
) {
const actual = partition(...input);
assertEquals(actual, expected, message);
}
Deno.test({
name: "[collections/partition] no mutation",
fn() {
const array = [1, 2, 3];
partition(array, (it) => it % 2 === 0);
assertEquals(array, [1, 2, 3]);
},
});
Deno.test({
name: "[collections/partition] empty input",
fn() {
partitionTest(
[[], () => true],
[[], []],
);
},
});
Deno.test({
name: "[collections/partition] all match",
fn() {
partitionTest(
[[2, 4, 6], (it) => it % 2 === 0],
[[2, 4, 6], []],
);
partitionTest(
[["foo", "bar"], (it) => it.length > 0],
[["foo", "bar"], []],
);
},
});
Deno.test({
name: "[collections/partition] none match",
fn() {
partitionTest(
[[3, 7, 5], (it) => it % 2 === 0],
[[], [3, 7, 5]],
);
partitionTest(
[["foo", "bar"], (it) => it.startsWith("z")],
[[], ["foo", "bar"]],
);
},
});
Deno.test({
name: "[collections/partition] some match",
fn() {
partitionTest(
[[13, 4, 13, 8], (it) => it % 2 === 0],
[[4, 8], [13, 13]],
);
partitionTest(
[["foo", "bar", ""], (it) => it.length > 0],
[["foo", "bar"], [""]],
);
},
});