diff options
author | Alexander Early <alexander.early@gmail.com> | 2017-04-06 22:17:49 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2017-04-06 22:19:23 -0700 |
commit | 3dc9f8f1e120f0c95f67221ac0d1a9bac7b88cd4 (patch) | |
tree | 18407f9b503e0b01a29536e02cbb1bcd9e541737 /mocha_test | |
parent | 1af382d62b535f255a699fa03a4043faa5d3514e (diff) | |
download | async-3dc9f8f1e120f0c95f67221ac0d1a9bac7b88cd4.tar.gz |
added tests for DLL, filter(), non-leaking empty()
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/linked_list.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/mocha_test/linked_list.js b/mocha_test/linked_list.js new file mode 100644 index 0000000..19cb155 --- /dev/null +++ b/mocha_test/linked_list.js @@ -0,0 +1,83 @@ +var DLL = require('../lib/internal/DoublyLinkedList').default; +var expect = require('chai').expect; + +describe('DoublyLinkedList', function () { + it('toArray', function() { + var list = new DLL(); + expect(list.toArray()).to.eql([]); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + expect(list.toArray()).to.eql([0, 1, 2, 3, 4]); + }); + + it('filter', function() { + var list = new DLL(); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + + list.filter(function (node) { + return node.data !== 3; + }) + + expect(list.toArray()).to.eql([0, 1, 2, 4]); + }); + + it('filter (head)', function() { + var list = new DLL(); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + + list.filter(function (node) { + return node.data !== 0; + }) + + expect(list.toArray()).to.eql([1, 2, 3, 4]); + }); + + it('filter (tail)', function() { + var list = new DLL(); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + + list.filter(function (node) { + return node.data !== 4; + }) + + expect(list.toArray()).to.eql([0, 1, 2, 3]); + }); + + it('filter (all)', function() { + var list = new DLL(); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + + list.filter(function (node) { + return node.data > 5; + }) + + expect(list.toArray()).to.eql([]); + }); + + it('empty', function() { + var list = new DLL(); + + for (var i = 0; i < 5; i++) { + list.push({data: i}); + } + + var empty = list.empty(); + + expect(list).to.equal(empty); + expect(list.toArray()).to.eql([]); + }); +}); |