|
| 1 | +const DLL = require('.'); |
| 2 | + |
| 3 | +describe('Doubly Linked List', () => { |
| 4 | + it('Doubly linked list should be class', () => { |
| 5 | + expect(typeof DLL.prototype.constructor).toEqual('function'); |
| 6 | + }); |
| 7 | + |
| 8 | + const doublyLinkedList = new DLL(); |
| 9 | + |
| 10 | + it('It should create a DLL', () => { |
| 11 | + expect(doublyLinkedList.head.next).toEqual(doublyLinkedList.tail); |
| 12 | + expect(doublyLinkedList.tail.previous).toEqual(doublyLinkedList.head); |
| 13 | + expect(doublyLinkedList.length()).toEqual(0); |
| 14 | + }); |
| 15 | + |
| 16 | + it('It should add at beginning (addAtBeginning)', () => { |
| 17 | + doublyLinkedList.addAtBeginning(1); |
| 18 | + doublyLinkedList.addAtBeginning(2); |
| 19 | + doublyLinkedList.addAtBeginning(3); |
| 20 | + expect(doublyLinkedList.traverse()).toEqual([3, 2, 1]); |
| 21 | + }); |
| 22 | + |
| 23 | + it('It should add at end (addAtEnd)', () => { |
| 24 | + doublyLinkedList.addAtEnd(1); |
| 25 | + doublyLinkedList.addAtEnd(2); |
| 26 | + doublyLinkedList.addAtEnd(3); |
| 27 | + expect(doublyLinkedList.traverse()).toEqual([3, 2, 1, 1, 2, 3]); |
| 28 | + }); |
| 29 | + |
| 30 | + it('It should remove at beginning (removeAtBeginning)', () => { |
| 31 | + doublyLinkedList.removeAtBeginning(); |
| 32 | + doublyLinkedList.removeAtBeginning(); |
| 33 | + doublyLinkedList.removeAtBeginning(); |
| 34 | + expect(doublyLinkedList.traverse()).toEqual([1, 2, 3]); |
| 35 | + }); |
| 36 | + |
| 37 | + it('It should remove at end (removeAtEnd)', () => { |
| 38 | + doublyLinkedList.removeAtEnd(); |
| 39 | + doublyLinkedList.removeAtEnd(); |
| 40 | + doublyLinkedList.removeAtEnd(); |
| 41 | + |
| 42 | + expect(doublyLinkedList.traverse()).toEqual([]); |
| 43 | + }); |
| 44 | +}); |
0 commit comments