Test that it is possible to use objects and binary tree node values.

This commit is contained in:
Oleksii Trekhleb
2018-05-30 07:19:48 +03:00
parent 625217a9c2
commit 3ae9c40416
2 changed files with 71 additions and 4 deletions

View File

@@ -173,4 +173,27 @@ describe('BinaryTreeNode', () => {
expect(root.left).toBeNull();
expect(root.right).toBeNull();
});
it('should be possible to create node with object as a value', () => {
const obj1 = { key: 'object_1', toString: () => 'object_1' };
const obj2 = { key: 'object_2' };
const node1 = new BinaryTreeNode(obj1);
const node2 = new BinaryTreeNode(obj2);
node1.setLeft(node2);
expect(node1.value).toEqual(obj1);
expect(node2.value).toEqual(obj2);
expect(node1.left.value).toEqual(obj2);
node1.removeChild(node2);
expect(node1.value).toEqual(obj1);
expect(node2.value).toEqual(obj2);
expect(node1.left).toBeNull();
expect(node1.toString()).toBe('object_1');
expect(node2.toString()).toBe('[object Object]');
});
});