Skip to content

Commit 13a6dfc

Browse files
committed
Slightly better testing.
1 parent 21a2546 commit 13a6dfc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

FastIntegerCompression.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,17 @@ FastIntegerCompression.compress = function(input) {
8080

8181
// from a compressed array of integers stored ArrayBuffer, compute the number of compressed integers by scanning the input
8282
FastIntegerCompression.computeHowManyIntegers = function(input) {
83-
var view = new UInt8Array(input);
83+
var view = new Int8Array(input);
8484
var c = view.length;
8585
var count = 0;
8686
for(var i = 0; i < c; i++) {
8787
count += (input[i]>>>7);
8888
}
8989
return c - count;
9090
}
91-
9291
// uncompress an array of integer from an ArrayBuffer, return the array
9392
FastIntegerCompression.uncompress = function(input) {
94-
var array = new Array()
93+
var array = []
9594
var inbyte = new Int8Array(input);
9695
var end = inbyte.length;
9796
var pos = 0;
@@ -128,7 +127,6 @@ FastIntegerCompression.uncompress = function(input) {
128127
};
129128

130129

131-
132130
///////////////
133131

134132
module.exports = FastIntegerCompression;

benchmark/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function BasicBench() {
1414
array.push(Math.round(Math.random() * t))
1515
}
1616
var buf = FastIntegerCompression.compress(array);
17+
FastIntegerCompression.uncompress(buf);
1718
console.log('input size: '+sizeof.format(sizeof.sizeof(array))+' compressed size: '+sizeof.format(buf.byteLength));
1819

1920
var suite = new Benchmark.Suite();

unit/basictests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('FastIntegerCompression', function() {
1717
it('Testing simple compression', function() {
1818
var array = [10,100000,65999,10,10,0,1,1,2000];
1919
var buf = FastIntegerCompression.compress(array);
20+
if(! FastIntegerCompression.computeHowManyIntegers(buf) == array.length) throw "bad count";
2021
var back = FastIntegerCompression.uncompress(buf);
2122
if(!arraysEquals(array,back)) throw "bad";
2223

0 commit comments

Comments
 (0)