[test] trying to test RedBlackTree

This commit is contained in:
Revone 2023-11-07 20:08:16 +08:00
parent 57a95e94db
commit c509a2d640
2 changed files with 17 additions and 1 deletions

View file

@ -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",

View file

@ -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', () => {
@ -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);
});
});