forked from knaxus/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidle-node.test.js
33 lines (29 loc) · 911 Bytes
/
midle-node.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
const { LinkedList } = require('../index');
const { getMiddleNode } = require('.');
describe('Find the middle node of a LinkedList', () => {
let list = null;
beforeEach(() => {
list = new LinkedList();
list.addAtBeginning('Hello');
list.addAtEnd('World!');
list.addAtEnd('Welcome');
list.addAtEnd('to');
list.addAtEnd('the');
list.addAtEnd('world');
list.addAtEnd('of');
list.addAtEnd('JavaScript');
});
it('Should return `null` for empty list', () => {
list.delete();
expect(getMiddleNode(list)).toEqual(null);
});
it('Should return `to` for the given list', () => {
expect(getMiddleNode(list).data).toEqual('to');
});
it('Should return `Welcome` after deleting 3 last nodes of the list', () => {
list.removeFromEnd();
list.removeFromEnd();
list.removeFromEnd();
expect(getMiddleNode(list).data).toEqual('Welcome');
});
});