forked from knaxus/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.test.js
51 lines (42 loc) · 1.42 KB
/
LinkedList.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
const { Node, LinkedList } = require('.');
describe('Data Structures: Linked Lists', () => {
describe('Node of a List', () => {
it('Should be a class', () => {
expect(typeof Node.prototype.constructor).toEqual('function');
});
it('Should set the data and next field of a node', () => {
const node = new Node('Hello', null);
expect(node.data).toEqual('Hello');
expect(node.next).toEqual(null);
});
});
describe('LinkedList Instance', () => {
it('Should be a class', () => {
expect(typeof LinkedList.prototype.constructor).toEqual('function');
});
it('Should set the data and next field of a node', () => {
const list = new LinkedList();
expect(list.head).not.toEqual(undefined);
expect(list.head).toEqual(null);
});
});
describe('LinkedList API', () => {
let list = new LinkedList();
beforeEach(() => {
list = new LinkedList();
});
it('Should add element at beginning using list.addAtBeginning()', () => {
list.addAtBeginning(12);
expect(list.head.data).toEqual(12);
list.addAtBeginning(15);
expect(list.head.data).toEqual(15);
});
it('Should return the present size of the list using list.length()', () => {
expect(list.length()).toEqual(0);
list.addAtBeginning(1);
list.addAtBeginning(2);
list.addAtBeginning(3);
expect(list.length()).toEqual(3);
});
});
});