-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
84 lines (72 loc) · 1.72 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
80
81
82
83
84
const { test } = require('tape-modern')
const { percent, integer, boolean } = require('./lib/random.js')
function printAvgs (samples, total) {
for (let name in samples) {
const sample = samples[name]
console.log('#', name)
for (let assert in sample) {
let percent = Math.round(sample[assert] / total * 1000000) / 10000
console.log('ok 1 -', assert, 'avg', percent + '%')
}
}
}
test('100k runs output frequency', t => {
const total = 100000
// Samples
const percentSamples = {
'0': 0,
'0.1': 0,
'0.2': 0,
'0.3': 0,
'0.4': 0,
'0.5': 0,
'0.6': 0,
'0.7': 0,
'0.8': 0,
'0.9': 0,
'1': 0,
}
const intSamples1 = {
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
'6': 0,
'7': 0,
'8': 0,
'9': 0,
'10': 0
}
const intSamples2 = {
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0
}
const booleanSamples = {
'true': 0,
'false': 0
}
for (let i = 0; i < total; i++) {
let val = Math.round(percent(i) * 10) / 10
if (!percentSamples[val]) percentSamples[val] = 1
else percentSamples[val]++
}
for (let i = 0; i < total; i++) {
intSamples1[integer(1, 10, i)]++
}
for (let i = 0; i < total; i++) {
intSamples2[integer(1, 5, i)]++
}
for (let i = 0; i < total; i++) {
booleanSamples[boolean(i)]++
}
printAvgs({
'percents': percentSamples,
'integers 1-5': intSamples1,
'integers 1-10': intSamples2,
'booleans': booleanSamples,
}, total)
})