-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoubly_linked_list.test.js
62 lines (47 loc) · 1.85 KB
/
doubly_linked_list.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var { DoublyLinkedList } = require('../dist/js-data-structs.cjs');
describe('Check Doubly Linked List methods', () => {
const list = DoublyLinkedList();
it('Should be able to tell if the list is empty or not', () => {
expect(list.isEmpty()).toBeTruthy();
expect(list.print()).toMatch('');
});
it('Should be able to insert to Head', () => {
list.insertHead('A');
list.insertHead('B');
list.insertHead('C');
expect(list.isEmpty()).toBeFalsy();
expect(list.print()).toMatch('C, B, A');
});
it('Should be able to insert to Tail', () => {
list.insertTail('D');
list.insertTail('E');
list.insertTail('F');
expect(list.isEmpty()).toBeFalsy();
expect(list.print()).toMatch('C, B, A, D, E, F');
});
it('Should be able to insert to specific position', () => {
list.insertAt('G', 1);
expect(list.isEmpty()).toBeFalsy();
expect(list.print()).toMatch('C, G, B, A, D, E, F');
expect(list.insertAt('H', -1)).toMatch('Index out of bounds');
});
it('Should be able to remove the Head', () => {
list.removeHead();
expect(list.isEmpty()).toBeFalsy();
expect(list.print()).toMatch('G, B, A, D, E, F');
});
it('Should be able to remove the Tail', () => {
list.removeTail();
expect(list.isEmpty()).toBeFalsy();
expect(list.print()).toMatch('G, B, A, D, E');
});
it('Should get the node in specific position', () => {
expect(list.getItemAt(1).value).toMatch('B');
expect(list.getItemAt(-1)).toMatch('Index out of bounds');
});
it('Should remove node from specific position', () => {
list.removeFrom(2);
expect(list.print()).toMatch('G, B, D, E');
expect(list.removeFrom(-1)).toMatch('Index out of bounds');
});
});