forked from trekhleb/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListNode.test.js
More file actions
46 lines (35 loc) · 1.33 KB
/
LinkedListNode.test.js
File metadata and controls
46 lines (35 loc) · 1.33 KB
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
import LinkedListNode from '../LinkedListNode';
describe('LinkedListNode', () => {
it('should create list node with value', () => {
const node = new LinkedListNode(1);
expect(node.value).toBe(1);
expect(node.next).toBeNull();
});
it('should create list node with object as a value', () => {
const nodeValue = { value: 1, key: 'test' };
const node = new LinkedListNode(nodeValue);
expect(node.value.value).toBe(1);
expect(node.value.key).toBe('test');
expect(node.next).toBeNull();
});
it('should link nodes together', () => {
const node2 = new LinkedListNode(2);
const node1 = new LinkedListNode(1, node2);
expect(node1.next).toBeDefined();
expect(node2.next).toBeNull();
expect(node1.value).toBe(1);
expect(node1.next.value).toBe(2);
});
it('should convert node to string', () => {
const node = new LinkedListNode(1);
expect(node.toString()).toBe('1');
node.value = 'string value';
expect(node.toString()).toBe('string value');
});
it('should convert node to string with custom stringifier', () => {
const nodeValue = { value: 1, key: 'test' };
const node = new LinkedListNode(nodeValue);
const toStringCallback = (value) => `value: ${value.value}, key: ${value.key}`;
expect(node.toString(toStringCallback)).toBe('value: 1, key: test');
});
});