chainy/node_modules/markov/test/has.js

34 lines
806 B
JavaScript
Raw Normal View History

2020-01-26 19:03:32 +00:00
var test = require('tape');
var markov = require('../');
var fs = require('fs');
test('has', function (t) {
var to = setTimeout(function () {
t.fail('never finished');
}, 5000);
var m = markov(1);
var these = 'constructor toLocaleString valueOf __defineGetter__';
m.seed(these, function () {
clearTimeout(to);
var counts = {};
for (var i = 0; i < 100; i++) {
var res = m.respond('the', 100);
t.ok(res.length < 100);
res.forEach(function (r) {
t.ok(these.split(' ').indexOf(r) >= 0);
counts[r] = (counts[r] || 0) + 1;
});
}
t.deepEqual(
Object.keys(counts).sort(),
these.split(' ').sort()
);
t.end();
});
});