-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
59 lines (53 loc) · 1.65 KB
/
index.test.ts
File metadata and controls
59 lines (53 loc) · 1.65 KB
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
import test from "ava";
import {entries, filter, keys, map, values} from "./index";
test("map", t => {
t.deepEqual(
map({a: 1, b: 2}, value => value + 1),
{a: 2, b: 3}
);
t.deepEqual(
map({a: 1, b: 2}, (value, key) => (value * 2).toString(10) + key),
{a: "2a", b: "4b"}
);
});
test("filter", t => {
const dictionary = {a: 1, b: 2, c: 3, d: 17, e: 24};
t.deepEqual(
filter(dictionary, value => value % 2 === 0),
{b: 2, e: 24}
);
t.deepEqual(
filter(dictionary, (value: number, key: string) => value % 2 === 1 && key !== "c"),
{a: 1, d: 17}
);
});
interface Furniture {
readonly hatstand: number;
readonly sofa: string;
}
test("keys", t => {
const furniture: Furniture = {hatstand: 3, sofa: "comfy"};
t.deepEqual(keys(furniture), ["hatstand", "sofa"]);
const dictionary: Record<string, number> = {a: 1, b: 2};
const dictionaryKeys: string[] = keys(dictionary);
t.deepEqual(dictionaryKeys, ["a", "b"]);
});
test("values", t => {
const furniture: Furniture = {hatstand: 3, sofa: "comfy"};
t.deepEqual(values(furniture), [3, "comfy"]);
const dictionary: Record<string, number> = {a: 1, b: 2};
t.deepEqual(values(dictionary), [1, 2]);
});
test("entries", t => {
const furniture: Furniture = {hatstand: 3, sofa: "comfy"};
t.deepEqual(entries(furniture), [
["hatstand", 3],
["sofa", "comfy"]
]);
const dictionary: Record<string, number> = {a: 1, b: 2};
const dictionaryEntries: Array<[string, number]> = entries(dictionary);
t.deepEqual(dictionaryEntries, [
["a", 1],
["b", 2]
]);
});