Skip to content

Commit

Permalink
clean up _check, omit slow bulk tests when doing coverage; 1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras committed May 7, 2017
1 parent b415bdd commit ffc6ab7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/qheap.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ Heap.prototype._trimArraySize = function Heap__trimArraySize( list, len ) {
}

Heap.prototype._check = function Heap__check( ) {
if (!this._compar) {
var isBefore = this._isBefore;
this._compar = function(a, b) { return isBefore(a, b) ? -1 : 1 };
}
var isBefore = this._isBefore;
var _compar = function(a, b) { return isBefore(a, b) ? -1 : 1 };

var i, p, fail = 0;
for (i=this.length; i>1; i--) {
Expand All @@ -126,8 +124,8 @@ Heap.prototype._check = function Heap__check( ) {
// swapping the values must change their ordering, otherwise the
// comparison is a tie. (Ie, consider the ordering func (a <= b)
// that for some values reports both that a < b and b < a.)
if (this._compar(this._list[p], this._list[i]) > 0 &&
this._compar(this._list[i], this._list[p]) < 0)
if (_compar(this._list[p], this._list[i]) > 0 &&
_compar(this._list[i], this._list[p]) < 0)
{
fail = i;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"scripts": {
"test": "qnit -t 10000 test/test-*",
"coverage": "nyc --reporter lcov --reporter text npm test",
"coverage": "env NODE_COVERAGE=1 nyc --reporter lcov --reporter text npm test",
"clean": "rm -rf .nyc_output coverage",
"coveralls": "nyc --reporter text-lcov npm test | & coveralls"
"coveralls": "env NODE_COVERAGE=1 nyc --reporter text-lcov npm test | & coveralls"
},
"dependencies": {
},
Expand Down
10 changes: 8 additions & 2 deletions test/test-qheap.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ module.exports = {
},

'should sort the data': function(t) {
if (process.env.NODE_COVERAGE) return t.done();
var i, data = [580, 253, 610, 176];
var nitems = 100000;
for (i=0; i<nitems; i++) {
Expand Down Expand Up @@ -208,19 +209,24 @@ module.exports = {

'_check should flag invalid heap': function(t) {
var h = new Heap();
h.push(1);
h.push(2);
var h2 = new Heap();
h.push(1); h2.push(1);
h.push(2); h2.push(2);
// break h
h._list[1] = 2;
h._list[2] = 1;
var stub = t.stub(console, 'log');
var ok = h._check();
var good = h2._check();
stub.restore();
t.assert(!ok);
t.assert(good);
t.done();
},
},

'fuzz test': function(t) {
if (process.env.NODE_COVERAGE) return t.done();
for (var nitems=2; nitems<8; nitems++) {
for (var loop=0; loop<20000; loop++) {
var cut = new Heap({size: 4});
Expand Down

0 comments on commit ffc6ab7

Please sign in to comment.