summaryrefslogtreecommitdiff
path: root/testes/sort.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/sort.lua')
-rw-r--r--testes/sort.lua23
1 files changed, 12 insertions, 11 deletions
diff --git a/testes/sort.lua b/testes/sort.lua
index ef405d92..52919b8c 100644
--- a/testes/sort.lua
+++ b/testes/sort.lua
@@ -20,7 +20,7 @@ end
checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4)
local x,y,z,a,n
-a = {}; lim = _soft and 200 or 2000
+a = {}; local lim = _soft and 200 or 2000
for i=1, lim do a[i]=i end
assert(select(lim, unpack(a)) == lim and select('#', unpack(a)) == lim)
x = unpack(a)
@@ -222,7 +222,7 @@ a = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
table.sort(a)
check(a)
-function perm (s, n)
+local function perm (s, n)
n = n or #s
if n == 1 then
local t = {unpack(s)}
@@ -248,7 +248,7 @@ perm{1,2,3,3,5}
perm{1,2,3,4,5,6}
perm{2,2,3,3,5,6}
-function timesort (a, n, func, msg, pre)
+local function timesort (a, n, func, msg, pre)
local x = os.clock()
table.sort(a, func)
x = (os.clock() - x) * 1000
@@ -257,7 +257,7 @@ function timesort (a, n, func, msg, pre)
check(a, func)
end
-limit = 50000
+local limit = 50000
if _soft then limit = 5000 end
a = {}
@@ -274,7 +274,7 @@ for i=1,limit do
a[i] = math.random()
end
-x = os.clock(); i=0
+local x = os.clock(); local i = 0
table.sort(a, function(x,y) i=i+1; return y<x end)
x = (os.clock() - x) * 1000
print(string.format("Invert-sorting other %d elements in %.2f msec., with %i comparisons",
@@ -289,18 +289,19 @@ timesort(a, limit, function(x,y) return nil end, "equal")
for i,v in pairs(a) do assert(v == false) end
-A = {"álo", "\0first :-)", "alo", "then this one", "45", "and a new"}
-table.sort(A)
-check(A)
+AA = {"álo", "\0first :-)", "alo", "then this one", "45", "and a new"}
+table.sort(AA)
+check(AA)
-table.sort(A, function (x, y)
- load(string.format("A[%q] = ''", x), "")()
+table.sort(AA, function (x, y)
+ load(string.format("AA[%q] = ''", x), "")()
collectgarbage()
return x<y
end)
+_G.AA = nil
-tt = {__lt = function (a,b) return a.val < b.val end}
+local tt = {__lt = function (a,b) return a.val < b.val end}
a = {}
for i=1,10 do a[i] = {val=math.random(100)}; setmetatable(a[i], tt); end
table.sort(a)