Skip to content
This repository has been archived by the owner on May 24, 2020. It is now read-only.

Commit

Permalink
fixed minor empty-arg validation bug
Browse files Browse the repository at this point in the history
added missing empty-arg on enqueue test
added test coverage util
  • Loading branch information
drora committed Jan 25, 2017
1 parent e0794d3 commit bf93e04
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
**/node_modules
**/npm-debug.log
**/.idea
**/coverage
**/reports
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ module.exports = class IQ {
this._members = members;
}
enqueue(o, friend = false) {
const oKey = o?(typeof o==='object')?hash(o):o:false,
if (!o) return false;
const oKey = (typeof o==='object')?hash(o):o,
friendKey = friend?(typeof friend==='object')?hash(friend):friend:false;
this._members[oKey] = !!(this._members[oKey]) ? ++(this._members[oKey]) : 1;
this._members[oKey] = (this._members[oKey]) ? ++(this._members[oKey]) : 1;
if (friend && this._members[friendKey]) {
let index = (typeof friend==='object')?false:(this._queue.indexOf(friend))+1;
if (index) {
this._queue.splice(index, 0, o);
return index + 1;
return ++index;
}
index = _.findIndex(this._queue, (member) => {
return hash(member)==friendKey;
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{
"name": "israeli-queue",
"version": "1.1.0",
"version": "1.1.1",
"description": "in-memory israeli-queue influenced by: http://www.math.tau.ac.il/~uriy/Papers/IQ-with-Priorities.pdf",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "Dror Arazi <dror@sealights.io> (www.sealights.io)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Sealights/israeli-queue.git"
},
"scripts": {
"test": "mocha",
"cover": "istanbul cover --report html node_modules/mocha/bin/_mocha -- -R spec",
"mutate": "stryker run stryker.conf.js"
},
"dependencies": {
"lodash": "^4.17.4",
"object-hash": "^1.1.5"
},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"stryker": "^0.5.7",
"stryker-api": "^0.4.2",
"stryker-html-reporter": "^0.3.0",
"stryker-mocha-runner": "^0.2.0"
},
"keywords": [
"israeli",
Expand Down
13 changes: 13 additions & 0 deletions stryker.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (config) {
config.set({
files: [
{pattern: './index.js', mutated: true, included: false},
'./test/test.js'
],
testRunner: 'mocha',
testFramework: 'mocha',
coverageAnalysis: 'perTest',
reporter: ['html', 'progress'],
logLevel: 'debug'
});
};
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ describe('IQ', () => {
queue = new IQ();
});

it('no member', () => {
queue.enqueue();
queue.enqueue(undefined, undefined);

queue.length().should.equal(0);
queue.peek().should.equal(false);
queue.dequeue().should.equal(false);

queue.toString().should.equal("[]");
});

it('one simple member', () => {
queue.enqueue(1);

Expand Down

0 comments on commit bf93e04

Please sign in to comment.