-
Notifications
You must be signed in to change notification settings - Fork 20
/
generate-tests.js
54 lines (48 loc) · 1 KB
/
generate-tests.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
const rndstr = require('random-string');
const fs = require('fs');
const crc32 = require('sse4_crc32').calculate;
const tests = {
string: {
cases: [],
},
buffer: {
cases: [],
}
};
for (let i = 0; i < 10; i++) {
const str = rndstr({
length: 1024,
});
tests.string.cases.push({
input: str,
want: crc32(str)
});
}
for (let i = 0; i < 10; i++) {
const buf = Buffer.alloc(1024);
for (let j = 0; j < 1024; j++) {
buf.writeUInt8(parseInt(Math.random() * 256), j);
}
tests.buffer.cases.push({
input: buf,
want: crc32(buf)
});
}
const strs = ['', '\0'];
strs.forEach(function(str) {
tests.string.cases.push({
input: str,
want: crc32(str),
});
const buf = Buffer.from(str, 'utf-8');
tests.buffer.cases.push({
input: buf,
want: crc32(buf),
});
});
for (const type in tests) {
tests[type].want = tests[type].cases.reduce(function(prev, cs) {
return crc32(cs.input, prev);
}, 0);
}
fs.writeFileSync('./test/sets.json', JSON.stringify(tests));