|
| 1 | +const expect = require('chai').expect; |
| 2 | +const Stack = require('../../examples/datastructures/stack'); |
| 3 | + |
| 4 | +describe('=> STACK', function() { |
| 5 | + let numbers; |
| 6 | + before(function () { |
| 7 | + numbers = new Stack(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should create an Empty Stack', function(done) { |
| 11 | + expect(numbers.dataStore).to.deep.equal([]); |
| 12 | + expect(numbers.top).to.equal(-1); |
| 13 | + done(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should push elements into the Stack', function(done) { |
| 17 | + numbers.push(1); |
| 18 | + numbers.push(2); |
| 19 | + numbers.push(3); |
| 20 | + numbers.push(4); |
| 21 | + expect(numbers.dataStore).to.deep.equal([1,2,3,4]); |
| 22 | + expect(numbers.top).to.equal(3); |
| 23 | + done(); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('=> pop', function() { |
| 27 | + |
| 28 | + it('should pop 1 element of the Stack', function(done) { |
| 29 | + numbers.pop(); |
| 30 | + expect(numbers.dataStore).to.deep.equal([1,2,3]); |
| 31 | + expect(numbers.top).to.equal(2); |
| 32 | + done(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should pop all elements of the Stack', function(done) { |
| 36 | + numbers.pop(); |
| 37 | + numbers.pop(); |
| 38 | + numbers.pop(); |
| 39 | + expect(numbers.dataStore).to.deep.equal([]); |
| 40 | + expect(numbers.top).to.equal(-1); |
| 41 | + done(); |
| 42 | + }); |
| 43 | + |
| 44 | + }); |
| 45 | + |
| 46 | + it('should peek the Stack', function(done) { |
| 47 | + expect(numbers.peek()).to.deep.equal(4); |
| 48 | + done(); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should check if the Stack is empty', function(done) { |
| 52 | + expect(numbers.empty()).to.equal(false); |
| 53 | + done(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should check the length of the Stack', function(done) { |
| 57 | + expect(numbers.length()).to.equal(4); |
| 58 | + done(); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('=> clear', function() { |
| 62 | + it('should clear the Stack', function(done) { |
| 63 | + numbers.clear(); |
| 64 | + expect(numbers.top).to.equal(-1); |
| 65 | + expect(numbers.dataStore).to.deep.equal([]); |
| 66 | + done(); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | +}); |
0 commit comments