-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlinkedList.test.js
53 lines (45 loc) · 1.58 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
52
53
import { LinkedList } from './linkedList';
describe('LinkedList', () => {
const sourceArr = [1, 2, 3, 4, 5];
it('LinkedList.from', () => {
const linkedList = LinkedList.from(sourceArr);
expect(linkedList.toArray()).toEqual(sourceArr);
expect(linkedList.toString()).toEqual(sourceArr.join());
expect(linkedList.size).toEqual(sourceArr.length);
});
it('linkedList.append', () => {
const linkedList = LinkedList.from(sourceArr);
linkedList.append(6);
linkedList.append(10);
expect(linkedList.toArray()).toEqual(sourceArr.concat([6, 10]));
expect(linkedList.size).toEqual(sourceArr.length + 2);
});
it('linkedList.getNode', () => {
const linkedList = LinkedList.from(sourceArr);
const node = linkedList.getNode(2);
expect(node.val).toEqual(3);
});
it('linkedList.insert', () => {
const linkedList = LinkedList.from(sourceArr);
linkedList.insert(0, 2);
linkedList.insert(1, 3);
expect(linkedList.toArray()).toEqual([2, 3, 1, 2, 3, 4, 5]);
});
it('linkedList.removeAt', () => {
const linkedList = LinkedList.from(sourceArr);
linkedList.removeAt(0);
linkedList.removeAt(1);
expect(linkedList.toArray()).toEqual([2, 4, 5]);
});
it('linkedList.indexOf', () => {
const linkedList = LinkedList.from(sourceArr);
expect(linkedList.indexOf(1)).toEqual(0);
expect(linkedList.indexOf(3)).toEqual(2);
});
it('linkedList.remove', () => {
const linkedList = LinkedList.from(sourceArr);
linkedList.remove(1);
linkedList.remove(3);
expect(linkedList.toArray()).toEqual([2, 4, 5]);
});
});