Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ashi009 committed Oct 4, 2019
1 parent c40a524 commit 63fa326
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions generate-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for (let i = 0; i < 10; i++) {
});
tests.string.cases.push({
input: str,
output: crc32(str)
want: crc32(str)
});
}

Expand All @@ -28,27 +28,27 @@ for (let i = 0; i < 10; i++) {
}
tests.buffer.cases.push({
input: buf,
output: crc32(buf)
want: crc32(buf)
});
}

const strs = ['', '\0'];
strs.forEach(function(str) {
tests.string.cases.push({
input: str,
output: crc32(str),
want: crc32(str),
});
const buf = Buffer.from(str, 'utf-8');
tests.buffer.cases.push({
input: buf,
output: crc32(buf),
want: crc32(buf),
});
});

for (const type in tests) {
tests[type].output = tests[type].cases.reduce(function(prev, cs) {
tests[type].want = tests[type].cases.reduce(function(prev, cs) {
return crc32(cs.input, prev);
}, 0);
}

fs.writeFileSync('./test/sets.json', JSON.stringify(tests));
fs.writeFileSync('./sets.json', JSON.stringify(tests));
4 changes: 2 additions & 2 deletions test/crc32c.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ function testCalculate(crc32) {
const set = sets[type];
set.cases.forEach(function(cs) {
it(util.format('should digest %j correctly', cs.input), function() {
crc32.calculate(cs.input).should.eql(cs.output);
crc32.calculate(cs.input).should.eql(cs.want);
});
});
it(util.format('should digest all %s correctly', type), function() {
set.cases.reduce(function(prev, cs) {
return crc32.calculate(cs.input, prev);
}, 0).should.eql(set.output);
}, 0).should.eql(set.want);
})
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/sets.json

Large diffs are not rendered by default.

0 comments on commit 63fa326

Please sign in to comment.