mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
Comply with ESM syntax.
This commit is contained in:
@ -234,39 +234,39 @@ const AVLTree = (function () {
|
||||
/**
|
||||
* A Code for Testing the AVLTree
|
||||
*/
|
||||
(function test () {
|
||||
const newAVL = new AVLTree()
|
||||
const size = Math.floor(Math.random() * 1000000)
|
||||
let uniques = 0
|
||||
let i, temp, j
|
||||
const array = []
|
||||
for (i = 0; i < size; i++) {
|
||||
temp = Math.floor(Math.random() * Number.MAX_VALUE)
|
||||
if (newAVL.add(temp)) {
|
||||
uniques++
|
||||
array.push(temp)
|
||||
}
|
||||
}
|
||||
if (newAVL.size !== uniques) {
|
||||
throw new Error('elements not inserted properly')
|
||||
}
|
||||
const findTestSize = Math.floor(Math.random() * uniques)
|
||||
for (i = 0; i < findTestSize; i++) {
|
||||
j = Math.floor(Math.random() * uniques)
|
||||
if (!newAVL.find(array[j])) {
|
||||
throw new Error('inserted elements not found')
|
||||
}
|
||||
}
|
||||
const deleteTestSize = Math.floor(uniques * Math.random())
|
||||
for (i = 0; i < deleteTestSize; i++) {
|
||||
j = Math.floor(Math.random() * uniques)
|
||||
temp = array[j]
|
||||
if (newAVL.find(temp)) {
|
||||
if (!newAVL.remove(temp)) {
|
||||
throw new Error('delete not working properly')
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
// (function test () {
|
||||
// const newAVL = new AVLTree()
|
||||
// const size = Math.floor(Math.random() * 1000000)
|
||||
// let uniques = 0
|
||||
// let i, temp, j
|
||||
// const array = []
|
||||
// for (i = 0; i < size; i++) {
|
||||
// temp = Math.floor(Math.random() * Number.MAX_VALUE)
|
||||
// if (newAVL.add(temp)) {
|
||||
// uniques++
|
||||
// array.push(temp)
|
||||
// }
|
||||
// }
|
||||
// if (newAVL.size !== uniques) {
|
||||
// throw new Error('elements not inserted properly')
|
||||
// }
|
||||
// const findTestSize = Math.floor(Math.random() * uniques)
|
||||
// for (i = 0; i < findTestSize; i++) {
|
||||
// j = Math.floor(Math.random() * uniques)
|
||||
// if (!newAVL.find(array[j])) {
|
||||
// throw new Error('inserted elements not found')
|
||||
// }
|
||||
// }
|
||||
// const deleteTestSize = Math.floor(uniques * Math.random())
|
||||
// for (i = 0; i < deleteTestSize; i++) {
|
||||
// j = Math.floor(Math.random() * uniques)
|
||||
// temp = array[j]
|
||||
// if (newAVL.find(temp)) {
|
||||
// if (!newAVL.remove(temp)) {
|
||||
// throw new Error('delete not working properly')
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })()
|
||||
|
||||
module.exports = AVLTree
|
||||
export { AVLTree }
|
||||
|
Reference in New Issue
Block a user