-
-
Save OrKoN/72c2e7fcf4beca2555e72079ff5c3893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// на маленьком файле | |
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