-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
79 lines (69 loc) · 2.09 KB
/
test.js
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
import assert from 'node:assert/strict'
import test from 'node:test'
import {min, top} from 'trigrams'
test('trigrams', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('trigrams')).sort(), [
'min',
'top'
])
})
})
test('top()[]', async function (t) {
const data = await top()
await t.test('should be an object', async function () {
for (const [code, value] of Object.entries(data)) {
assert.strictEqual(typeof value, 'object', code + ' should be an object')
}
})
await t.test('should contain 300 values', async function () {
for (const [code, value] of Object.entries(data)) {
assert.strictEqual(
Object.keys(value).length,
300,
code + ' should have 300 values'
)
}
})
await t.test('should contain integers', async function () {
for (const [code, value] of Object.entries(data)) {
for (const [trigram, count] of Object.entries(value)) {
assert.strictEqual(
typeof count,
'number',
trigram + ' in ' + code + ' should be a number'
)
assert.strictEqual(
Math.round(count),
count,
trigram + ' in ' + code + ' should be an integer'
)
}
}
})
})
test('min()[]', async function (t) {
const data = await min()
await t.test('should be an array', async function () {
for (const [code, value] of Object.entries(data)) {
assert.ok(Array.isArray(value), code + ' should be an array')
}
})
await t.test('should contain 300 values', async function () {
for (const [code, value] of Object.entries(data)) {
assert.strictEqual(value.length, 300, code + ' should have 300 values')
}
})
await t.test('should contain strings', async function () {
for (const [code, value] of Object.entries(data)) {
let index = -1
while (++index < value.length) {
assert.strictEqual(
typeof value[index],
'string',
index + ' in ' + code + ' should be a string'
)
}
}
})
})