* Split core lib into multiple files * Refactor data encoding methods * Refactor data masking process * Improve qr code generation process * Increase minimum required node version to 0.10 * Add linter * Add tests and tests coverage * Update travis config to fix compilation issues * Add examples folder * Add missing license tag in package.json * Update build script and add sourcemap support * Publish only strictly needed files on npm * Update readme
29 lines
978 B
JavaScript
29 lines
978 B
JavaScript
var test = require('tap').test
|
|
var RS = require('core/reed-solomon-encoder')
|
|
|
|
test('Reed-Solomon encoder', function (t) {
|
|
var enc = new RS()
|
|
|
|
t.notOk(enc.genPoly, 'Should have an undefined generator polynomial')
|
|
t.throw(function () { enc.encode([]) }, 'Should throw if generator polynomial is undefined')
|
|
|
|
enc.initialize(2)
|
|
t.equal(enc.degree, 2, 'Should set correct degree value')
|
|
t.ok(enc.genPoly, 'Generator polynomial should be defined')
|
|
|
|
var result = enc.encode(new Buffer('01234'))
|
|
t.equal(result.length, 2, 'Should return a number of codewords equal to gen poly degree')
|
|
|
|
enc = new RS(2)
|
|
var genPoly = enc.genPoly
|
|
t.equal(enc.degree, 2, 'Should set correct degree value')
|
|
t.ok(genPoly, 'Generator polynomial should be defined')
|
|
|
|
enc.initialize(3)
|
|
t.notEqual(enc.genPoly, genPoly, 'Should reinitialize the generator polynomial')
|
|
|
|
enc = new RS(0)
|
|
t.notOk(enc.genPoly, 'Should not create a generator polynomial if degree is 0')
|
|
|
|
t.end()
|
|
})
|