'use_strict'; const assert = require('assert'); const mocha = require('mocha'); const ReedSolomon = require('@ronomon/reed-solomon'); [1, 2].forEach( m => [0, 0xff].forEach( initValue => mocha.it(`Test parity initialization - m=${m}, initValue=${initValue}`, function (done) { const k = 2; const ctx = ReedSolomon.create(k, m); const size = 8; const dataBuffer = Buffer.concat([ Buffer.alloc(size, 0x42), Buffer.alloc(size, 0x66), ]); const parityBuffer = Buffer.alloc(m * size, initValue); const expectedParity1 = Buffer.alloc(size, 0x42 ^ 0x66); const sources = (1 << k) - 1; const targets = ((1 << m) - 1) << k; ReedSolomon.encode( ctx, sources, targets, dataBuffer, 0, dataBuffer.length, parityBuffer, 0, parityBuffer.length, err => { assert.ifError(err); const toCompare = parityBuffer.slice(0, size); const cmp = Buffer.compare(toCompare, expectedParity1); if (cmp !== 0) { assert.strictEqual(toCompare, expectedParity1); } done(); } ); }) ) );