Comply with ESM syntax.

This commit is contained in:
Eric Lavault
2021-10-09 13:18:40 +02:00
parent 5a290c3ae5
commit cbe7e0c89f
16 changed files with 50 additions and 62 deletions

View File

@ -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 }