-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
45 lines (35 loc) · 1.06 KB
/
index.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
const { Node } = require('.');
test('should initialize an empty array', () => {
// Arrange & Act
const linkedList = new Node();
// Assert
expect(linkedList.size()).toEqual(1);
})
test('should initialize linked with three nodes', () => {
// Arrange & Act
const linkedList = new Node(1, new Node(2, new Node (3)));
// Assert
expect(linkedList.size()).toEqual(3);
})
test('should add a new node in the linkedList', () => {
// Arrange
const linkedList = new Node(1, new Node(2, new Node (3)));
// Act
linkedList.add(new Node(4))
// Assert
expect(linkedList.size()).toEqual(4);
})
/**
* https://www.geeksforgeeks.org/reverse-a-linked-list/
*/
test('should reverse linked list nodes', () => {
// Arrange
const head = new Node(1, new Node(2, new Node(3)))
// Act
const revertedLinkedList = Node.reverse(head);
// Assert
expect(revertedLinkedList.size()).toEqual(3);
expect(revertedLinkedList.value).toEqual(3);
expect(revertedLinkedList.next.value).toEqual(2);
expect(revertedLinkedList.next.next.value).toEqual(1);
});