aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-16 17:05:22 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-09-16 17:05:22 -0300
commitf8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51 (patch)
treeeaa1409a4f92e90a1f971a57f68b94d72ac9d651
parent71bc69c2afaf49ab5f54f3443af9ae70dd1fed06 (diff)
downloadlua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.tar.gz
lua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.tar.bz2
lua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.zip
New test for table rehash
-rw-r--r--testes/nextvar.lua38
1 files changed, 29 insertions, 9 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 9e23e572..0874e5bb 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -9,6 +9,16 @@ local function checkerror (msg, f, ...)
9end 9end
10 10
11 11
12local function check (t, na, nh)
13 if not T then return end
14 local a, h = T.querytab(t)
15 if a ~= na or h ~= nh then
16 print(na, nh, a, h)
17 assert(nil)
18 end
19end
20
21
12local a = {} 22local a = {}
13 23
14-- make sure table has lots of space in hash part 24-- make sure table has lots of space in hash part
@@ -20,6 +30,25 @@ for i=1,100 do
20 assert(#a == i) 30 assert(#a == i)
21end 31end
22 32
33
34do -- rehash moving elements from array to hash
35 local a = {}
36 for i = 1, 100 do a[i] = i end
37 check(a, 128, 0)
38
39 for i = 5, 95 do a[i] = nil end
40 check(a, 128, 0)
41
42 a.x = 1 -- force a re-hash
43 check(a, 4, 8)
44
45 for i = 1, 4 do assert(a[i] == i) end
46 for i = 5, 95 do assert(a[i] == nil) end
47 for i = 96, 100 do assert(a[i] == i) end
48 assert(a.x == 1)
49end
50
51
23-- testing ipairs 52-- testing ipairs
24local x = 0 53local x = 0
25for k,v in ipairs{10,20,30;x=12} do 54for k,v in ipairs{10,20,30;x=12} do
@@ -65,15 +94,6 @@ local function mp2 (n) -- minimum power of 2 >= n
65end 94end
66 95
67 96
68local function check (t, na, nh)
69 local a, h = T.querytab(t)
70 if a ~= na or h ~= nh then
71 print(na, nh, a, h)
72 assert(nil)
73 end
74end
75
76
77-- testing C library sizes 97-- testing C library sizes
78do 98do
79 local s = 0 99 local s = 0