Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26d6b78

Browse files
committed
Improve test-coverage for red-black tree.
1 parent 19789c6 commit 26d6b78

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎src/data-structures/tree/red-black-tree/__test__/RedBlackTree.test.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,30 @@ describe('RedBlackTree', () => {
285285
expect(tree.isNodeRed(node3)).toBeTruthy();
286286
expect(tree.isNodeRed(node6)).toBeTruthy();
287287
});
288+
289+
it('should do left-left rotation with left grand-parent', () => {
290+
const tree = new RedBlackTree();
291+
292+
tree.insert(20);
293+
tree.insert(15);
294+
tree.insert(25);
295+
tree.insert(10);
296+
tree.insert(5);
297+
298+
expect(tree.toString()).toBe('5,10,15,20,25');
299+
expect(tree.root.height).toBe(2);
300+
});
301+
302+
it('should do right-right rotation with left grand-parent', () => {
303+
const tree = new RedBlackTree();
304+
305+
tree.insert(20);
306+
tree.insert(15);
307+
tree.insert(25);
308+
tree.insert(17);
309+
tree.insert(19);
310+
311+
expect(tree.toString()).toBe('15,17,19,20,25');
312+
expect(tree.root.height).toBe(2);
313+
});
288314
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /