deno.land / std@0.166.0 / collections / reduce_groups_test.ts

reduce_groups_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";import { reduceGroups } from "./reduce_groups.ts";
function reduceGroupsTest<T, A>( input: [Record<string, Array<T>>, (accumulator: A, current: T) => A, A], expected: Record<string, A>, message?: string,) { const actual = reduceGroups(...input); assertEquals(actual, expected, message);}
Deno.test({ name: "[collections/mapEntries] no mutation", fn() { const input = { Woody: [2, 3, 1, 4], Buzz: [5, 9], };
reduceGroups(input, (sum, it) => sum + it, 0);
assertEquals(input, { Woody: [2, 3, 1, 4], Buzz: [5, 9], }); },});
Deno.test({ name: "[collections/mapEntries] array of numbers", fn() { reduceGroupsTest( [ { Woody: [2, 3, 1, 4], Buzz: [5, 9], }, (sum, it) => sum + it, 0, ], { Woody: 10, Buzz: 14, }, ); },});
Deno.test({ name: "[collections/mapEntries] array of string", fn() { reduceGroupsTest( [ { Woody: ["foo", "bar"], Buzz: ["foo", "bar", "baz"], }, (sum, it) => sum + it + " ", "", ], { Woody: "foo bar ", Buzz: "foo bar baz ", }, ); },});
Deno.test({ name: "[collections/mapEntries] mapper", fn() { reduceGroupsTest( [ { Woody: [{ val: 14 }, { val: 24 }], Buzz: [{ val: 1 }, { val: 2 }, { val: 3 }, { val: 4 }], }, (sum, it) => sum + it.val, 0, ], { Woody: 38, Buzz: 10, }, ); },});
Deno.test({ name: "[collections/mapEntries] initial value", fn() { reduceGroupsTest( [ { Woody: [], Buzz: [], }, (sum, it) => sum + it, 24, ], { Woody: 24, Buzz: 24, }, ); },});
Deno.test({ name: "[collections/mapEntries] empty input", fn() { reduceGroupsTest([{}, () => 0, 0], {}); },});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago