mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Test that it is possible to use objects and binary tree node values.
This commit is contained in:
@@ -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]');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user