-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfuzz.js
66 lines (56 loc) · 1.33 KB
/
fuzz.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
'use strict';
var hDiff = require('./index');
function genRandom(len, max) {
return (new Array(
Math.floor(Math.random() * 26)
)).fill(0)
.map(v => String.fromCharCode(
Math.floor(Math.random() * len) + 97
));
}
function verify(d, l, r, out) {
var lr = d.filter(v =>
v.type === 'same' || v.type === 'del'
).reduce((acc, cur) =>
acc + cur.value
, '');
var rr = d.filter(v =>
v.type === 'same' || v.type === 'ins'
).reduce((acc, cur) =>
acc + cur.value
, '');
if (out) {
console.log(l.join(''), r.join(''));
console.log(lr, rr);
}
return l.join('') === lr && r.join('') === rr;
}
var left, right, diff;
for (var i = 0; i < 26; i++) {
process.stdout.write('.');
for (var j = 0; j < 10000; j++) {
left = genRandom(i, 26);
right = genRandom(i, 26);
diff = hDiff.diff(left, right);
if (!verify(diff, left, right)) {
verify(diff, left, right, true);
console.log(diff);
process.exit();
}
}
}
console.log();
for (var i = 0; i < 26; i++) {
process.stdout.write('.');
for (var j = 0; j < 10000; j++) {
left = genRandom(i, 1000);
right = genRandom(i, 1000);
diff = hDiff.diff(left, right);
if (!verify(diff, left, right)) {
verify(diff, left, right, true);
console.log(diff);
process.exit();
}
}
}
console.log();