From d30b45ac945984ee44783bc32cd765e03bea9a84 Mon Sep 17 00:00:00 2001 From: noevents Date: Wed, 26 Jul 2017 20:54:45 +0300 Subject: [PATCH 1/2] fix with test coverage --- index.js | 2 +- test/denque.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4b18732..a10b0d8 100644 --- a/index.js +++ b/index.js @@ -329,7 +329,7 @@ Denque.prototype.splice = function splice(index, count) { if(count === 0){ removed = []; if(i != size){ - this._tail = (i - 1 + len) & this._capacityMask; + this._tail = (this._head + i + len) & this._capacityMask; } } else { removed = this.remove(i, count); diff --git a/test/denque.js b/test/denque.js index 8b2eccf..7d67334 100644 --- a/test/denque.js +++ b/test/denque.js @@ -655,6 +655,12 @@ describe('Denque.prototype.splice', function () { b.unshift(1, 2, 3); b.splice(b.length,0, 17, 18, 19); assert.deepEqual(a.toArray(), b); + a.splice(18, 0, 18, 19); + b.splice(18, 0, 18, 19); + assert.deepEqual(a.toArray(), b); + a.splice(21, 0, 1, 2, 3, 4, 5, 6); + b.splice(21, 0, 1, 2, 3, 4, 5, 6); + assert.deepEqual(a.toArray(), b); assert.deepEqual(a.splice(a.length-1,2), b.splice(b.length-1,2)); //remove assert.deepEqual(a.toArray(), b); }); From 867d6922bbb53a42b2935064c57c4abec6e3cbec Mon Sep 17 00:00:00 2001 From: noevents Date: Wed, 26 Jul 2017 21:52:20 +0300 Subject: [PATCH 2/2] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3069e8b..29d12ee 100644 --- a/index.js +++ b/index.js @@ -328,7 +328,7 @@ Denque.prototype.splice = function splice(index, count) { } if (count === 0) { removed = []; - if(i != size){ + if (i != size) { this._tail = (this._head + i + len) & this._capacityMask; } } else {