UNPKG

dist-javascript-algorithms-and-data-structures

Version:

Algorithms and data-structures implemented on JavaScript

57 lines (52 loc) 2.02 kB
"use strict"; var _DoublyLinkedListNode = _interopRequireDefault(require("../DoublyLinkedListNode")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe('DoublyLinkedListNode', () => { it('should create list node with value', () => { const node = new _DoublyLinkedListNode.default(1); expect(node.value).toBe(1); expect(node.next).toBeNull(); expect(node.previous).toBeNull(); }); it('should create list node with object as a value', () => { const nodeValue = { value: 1, key: 'test' }; const node = new _DoublyLinkedListNode.default(nodeValue); expect(node.value.value).toBe(1); expect(node.value.key).toBe('test'); expect(node.next).toBeNull(); expect(node.previous).toBeNull(); }); it('should link nodes together', () => { const node2 = new _DoublyLinkedListNode.default(2); const node1 = new _DoublyLinkedListNode.default(1, node2); const node3 = new _DoublyLinkedListNode.default(10, node1, node2); expect(node1.next).toBeDefined(); expect(node1.previous).toBeNull(); expect(node2.next).toBeNull(); expect(node2.previous).toBeNull(); expect(node3.next).toBeDefined(); expect(node3.previous).toBeDefined(); expect(node1.value).toBe(1); expect(node1.next.value).toBe(2); expect(node3.next.value).toBe(1); expect(node3.previous.value).toBe(2); }); it('should convert node to string', () => { const node = new _DoublyLinkedListNode.default(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 _DoublyLinkedListNode.default(nodeValue); const toStringCallback = value => `value: ${value.value}, key: ${value.key}`; expect(node.toString(toStringCallback)).toBe('value: 1, key: test'); }); });