Skip to content

Commit 1cdd39f

Browse files
committed
feat: move demo functions to tests
1 parent 2a8b4a4 commit 1cdd39f

File tree

1 file changed

+1
-66
lines changed

1 file changed

+1
-66
lines changed

Sorts/IntroSort.js

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -241,69 +241,4 @@ function introsort(array, compare) {
241241
})(array, compare)
242242
}
243243

244-
/**
245-
* @example Demo run of the sort routine
246-
* The data is randomly generated
247-
* Returns 'RIGHT:)' if the sort routine worked as expected,
248-
* 'WRONG!!' otherwise
249-
*/
250-
function demo1() {
251-
const data = []
252-
const size = 1000000
253-
let i = 0
254-
let temp
255-
const c = function (a, b) {
256-
return a - b
257-
}
258-
for (i = 0; i < size; i++) {
259-
temp = Math.random() * Number.MAX_SAFE_INTEGER
260-
data.push(temp)
261-
}
262-
introsort(data, c)
263-
let faulty = false
264-
for (i = 1; i < size; i++) {
265-
if (data[i] < data[i - 1]) {
266-
faulty = true
267-
break
268-
}
269-
}
270-
if (faulty) {
271-
return 'WRONG!!'
272-
} else {
273-
return 'RIGHT:)'
274-
}
275-
}
276-
277-
/**
278-
* @example Demo run of the sort routine
279-
* using the default compare function and
280-
* comparing the results with Array.sort
281-
*/
282-
function demo2() {
283-
const data = []
284-
const data2 = []
285-
const size = 1000000
286-
let i = 0
287-
let temp
288-
for (i = 0; i < size; i++) {
289-
temp = Math.random() * Number.MAX_SAFE_INTEGER
290-
data.push(temp)
291-
data2.push(temp)
292-
}
293-
introsort(data)
294-
data2.sort()
295-
let faulty = false
296-
for (i = 1; i < size; i++) {
297-
if (data[i] !== data2[i]) {
298-
faulty = true
299-
break
300-
}
301-
}
302-
if (faulty) {
303-
return 'WRONG Implemented Comparator!!'
304-
} else {
305-
return 'Comparator Works Fine:)'
306-
}
307-
}
308-
309-
export { introsort, demo1, demo2 }
244+
export { introsort }

0 commit comments

Comments
 (0)