Skip to content

Commit 69c973a

Browse files
committedOct 25, 2019
--update : add doublyLinkedList test
1 parent 29bfb14 commit 69c973a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const DLL = require('.');
2+
3+
describe('Doubly Linked List', () => {
4+
const doublyLinkedList = new DLL();
5+
6+
it('create DLL', () => {
7+
expect(doublyLinkedList.head.next).toEqual(doublyLinkedList.tail);
8+
expect(doublyLinkedList.tail.previous).toEqual(doublyLinkedList.head);
9+
expect(doublyLinkedList.length()).toEqual(0);
10+
});
11+
12+
it('addAtBeginning', () => {
13+
doublyLinkedList.addAtBeginning(1);
14+
doublyLinkedList.addAtBeginning(2);
15+
doublyLinkedList.addAtBeginning(3);
16+
expect(doublyLinkedList.traverse()).toEqual([3, 2, 1]);
17+
});
18+
19+
it('addAtEnd', () => {
20+
doublyLinkedList.addAtEnd(1);
21+
doublyLinkedList.addAtEnd(2);
22+
doublyLinkedList.addAtEnd(3);
23+
expect(doublyLinkedList.traverse()).toEqual([3, 2, 1, 1, 2, 3]);
24+
});
25+
26+
it('removeAtBeginning', () => {
27+
doublyLinkedList.removeAtBeginning();
28+
doublyLinkedList.removeAtBeginning();
29+
doublyLinkedList.removeAtBeginning();
30+
expect(doublyLinkedList.traverse()).toEqual([1, 2, 3]);
31+
});
32+
33+
it('removeAtEnd', () => {
34+
doublyLinkedList.removeAtEnd();
35+
doublyLinkedList.removeAtEnd();
36+
doublyLinkedList.removeAtEnd();
37+
38+
expect(doublyLinkedList.traverse()).toEqual([]);
39+
});
40+
});

0 commit comments

Comments
 (0)