Skip to content

Instantly share code, notes, and snippets.

@OrKoN

OrKoN/test.js Secret

Created May 18, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrKoN/72c2e7fcf4beca2555e72079ff5c3893 to your computer and use it in GitHub Desktop.
Save OrKoN/72c2e7fcf4beca2555e72079ff5c3893 to your computer and use it in GitHub Desktop.
// на маленьком файле
describe('word-challenge', () => {
it('should work', () => {
const test = require('./full.json');
let count = 0;
let countTrue = 0;
let countFalse = 0;
Object.keys(test).forEach(w => {
if (test[w] === true) {
countTrue++;
} else {
countFalse++;
}
if (m.test(w) === test[w]) {
count++;
}
});
console.log('Rate = ', (count / Object.keys(test).length)*100);
console.log('countTrue = ', countTrue);
console.log('countFalse = ', countFalse);
});
});
// на большом файле
describe('word-challenger', () => {
it('should work', (done) => {
var fs = require('fs'),
byline = require('byline');
var stream = byline(fs.createReadStream(__dirname + '/all.txt', { encoding: 'utf8' }));
let count = 0;
let countTrue = 0;
let countFalse = 0;
stream.on('data', function(line) {
line = line.trim();
var spl = line.split(':');
var answer = (spl[1].trim() === 'true' || spl[1].trim() === 'true,') ? true : false;
var word = spl[0].trim().substring(1, spl[0].trim().length - 1);
if (answer === true) {
countTrue++;
} else {
countFalse++;
}
if (m.test(word) === answer) {
count++;
}
});
stream.on('end', () => {
console.log('Rate = ', (count / (countTrue+countFalse))*100);
console.log('countTrue = ', countTrue);
console.log('countFalse = ', countFalse);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment