Skip to content

Commit

Permalink
[test] trying to test RedBlackTree
Browse files Browse the repository at this point in the history
  • Loading branch information
zrwusa committed Nov 7, 2023
1 parent 57a95e9 commit c509a2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.42.3",
"version": "1.42.4",
"description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.",
"main": "dist/cjs/src/index.js",
"module": "dist/mjs/src/index.js",
Expand Down
16 changes: 16 additions & 0 deletions test/unit/data-structures/binary-tree/rb-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ describe('RedBlackTree', () => {
82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99
])
expect(tree.dfs( n => n.key, "in", tree.root, IterationType.RECURSIVE)).toEqual([
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99
])
});

it('should fix the tree after large scale insertion and deletion', () => {
Expand All @@ -460,6 +467,15 @@ describe('RedBlackTree', () => {
expect(tree.size).toBe(0);
expect(tree.isBST()).toBe(true);
expect(tree.dfs( n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([])

tree.clear();
for (let i = 0; i < 1000; i++) {
tree.add(getRandomInt(-100, 1000))
tree.delete(getRandomInt(-100, 1000))
}

// TODO there is a bug when dfs the tree with NIL node
// expect(tree.isBST()).toBe(true);
});

});

0 comments on commit c509a2d

Please sign in to comment.