aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/sort.lua29
1 files changed, 17 insertions, 12 deletions
diff --git a/testes/sort.lua b/testes/sort.lua
index 7e566a5a..442b3129 100644
--- a/testes/sort.lua
+++ b/testes/sort.lua
@@ -3,19 +3,30 @@
3 3
4print "testing (parts of) table library" 4print "testing (parts of) table library"
5 5
6local maxI = math.maxinteger
7local minI = math.mininteger
8
9
10local function checkerror (msg, f, ...)
11 local s, err = pcall(f, ...)
12 assert(not s and string.find(err, msg))
13end
14
15
6do print "testing 'table.create'" 16do print "testing 'table.create'"
17 local N = 10000
7 collectgarbage() 18 collectgarbage()
8 local m = collectgarbage("count") * 1024 19 local m = collectgarbage("count") * 1024
9 local t = table.create(10000) 20 local t = table.create(N)
10 local memdiff = collectgarbage("count") * 1024 - m 21 local memdiff = collectgarbage("count") * 1024 - m
11 assert(memdiff > 10000 * 4) 22 assert(memdiff > N * 4)
12 for i = 1, 20 do 23 for i = 1, 20 do
13 assert(#t == i - 1) 24 assert(#t == i - 1)
14 t[i] = 0 25 t[i] = 0
15 end 26 end
16 for i = 1, 20 do t[#t + 1] = i * 10 end 27 for i = 1, 20 do t[#t + 1] = i * 10 end
17 assert(#t == 40 and t[39] == 190) 28 assert(#t == 40 and t[39] == 190)
18 assert(not T or T.querytab(t) == 10000) 29 assert(not T or T.querytab(t) == N)
19 t = nil 30 t = nil
20 collectgarbage() 31 collectgarbage()
21 m = collectgarbage("count") * 1024 32 m = collectgarbage("count") * 1024
@@ -23,6 +34,9 @@ do print "testing 'table.create'"
23 memdiff = collectgarbage("count") * 1024 - m 34 memdiff = collectgarbage("count") * 1024 - m
24 assert(memdiff > 1024 * 12) 35 assert(memdiff > 1024 * 12)
25 assert(not T or select(2, T.querytab(t)) == 1024) 36 assert(not T or select(2, T.querytab(t)) == 1024)
37
38 checkerror("table overflow", table.create, (1<<31) + 1)
39 checkerror("table overflow", table.create, 0, (1<<31) + 1)
26end 40end
27 41
28 42
@@ -30,15 +44,6 @@ print "testing unpack"
30 44
31local unpack = table.unpack 45local unpack = table.unpack
32 46
33local maxI = math.maxinteger
34local minI = math.mininteger
35
36
37local function checkerror (msg, f, ...)
38 local s, err = pcall(f, ...)
39 assert(not s and string.find(err, msg))
40end
41
42 47
43checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4) 48checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4)
44 49