mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-18 09:23:55 +08:00

* Improving the coding standard for AvLTree Data Structure * Test case creation for AVLTree ~ Created test cases for AVL Tree ~ Indentation fix for AVLTree.js * Auto-update DIRECTORY.md * Change in logic for data list * Style fix based on standard.js Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
31 lines
725 B
JavaScript
31 lines
725 B
JavaScript
import { AVLTree } from '../AVLTree'
|
|
|
|
describe('AVLTree Implementation: ', () => {
|
|
const avlTree = new AVLTree()
|
|
const dataList = []
|
|
const demoData = [1, 4, 6, 22, 7, 99, 4, 66, 77, 98]
|
|
|
|
beforeAll(() => {
|
|
demoData.forEach(item => {
|
|
if (avlTree.add(item)) {
|
|
dataList.push(item)
|
|
}
|
|
})
|
|
})
|
|
|
|
it('checks if element is inserted properly', () => {
|
|
expect(dataList.length).toEqual(avlTree.size)
|
|
})
|
|
|
|
it('search if inserted element is present', () => {
|
|
demoData.forEach(data => {
|
|
expect(avlTree.find(data)).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
it('deletes the inserted element', () => {
|
|
const deleteElement = dataList[3]
|
|
expect(avlTree.remove(deleteElement)).toBeTruthy()
|
|
})
|
|
})
|