UNPKG

ds-algo-study

Version:

Just experimenting with publishing a package

37 lines (32 loc) 830 B
const Stack = require('./index'); test('Stack is a class', () => { expect(typeof Stack.prototype.constructor).toEqual('function'); }); test('stack can add and remove items', () => { const s = new Stack(); s.push(1); expect(s.pop()).toEqual(1); s.push(2); expect(s.pop()).toEqual(2); }); test('stack can follows first in, last out', () => { const s = new Stack(); s.push(1); s.push(2); s.push(3); expect(s.pop()).toEqual(3); expect(s.pop()).toEqual(2); expect(s.pop()).toEqual(1); }); test('peek returns the first element but doesnt pop it', () => { const s = new Stack(); s.push(1); s.push(2); s.push(3); expect(s.peek()).toEqual(3); expect(s.pop()).toEqual(3); expect(s.peek()).toEqual(2); expect(s.pop()).toEqual(2); expect(s.peek()).toEqual(1); expect(s.pop()).toEqual(1); });