-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
66 lines (55 loc) · 1.12 KB
/
Copy pathtest.lua
File metadata and controls
66 lines (55 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local sort = require("HeapSort")
-- local sort = require("QuickSort")
-- local sort = require("ShellSort")
math.randomseed(os.time());
function randomData()
local a = {};
for i=1,100 do
-- for i=1,10 do
table.insert(a, math.random(100))
end
-- a = {45, 15, 12}
return a;
end
local defaultSortFunc = function (a, b)
return a <= b
end
function swap(arr, i, j)
arr[i], arr[j] = arr[j], arr[i]
end
function varify(arr, func)
local pre
for i,v in ipairs(arr) do
if(pre and not func(pre, v))then
printt(arr)
return false;
end
pre = v
end
return true
end
function printt(t, i, j)
i = i or 1
j = j or #t;
local str = "";
for index = i, j do
str = str .. t[index] .. ", "
end
print(str)
end
function test()
local func = defaultSortFunc;
local data = randomData();
sort(data, func);
return varify(data, func);
end
function bench()
for i=1,10 do
if(not test()) then
print("sort failed")
return
end
end
print("sort successed")
end
bench();