diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-09-16 17:05:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-09-16 17:05:22 -0300 |
commit | f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51 (patch) | |
tree | eaa1409a4f92e90a1f971a57f68b94d72ac9d651 | |
parent | 71bc69c2afaf49ab5f54f3443af9ae70dd1fed06 (diff) | |
download | lua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.tar.gz lua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.tar.bz2 lua-f8c4c4fcf2b2fed00b3c5b71c19cd64e539dee51.zip |
New test for table rehash
-rw-r--r-- | testes/nextvar.lua | 38 |
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, ...) | |||
9 | end | 9 | end |
10 | 10 | ||
11 | 11 | ||
12 | local 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 | ||
19 | end | ||
20 | |||
21 | |||
12 | local a = {} | 22 | local 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) |
21 | end | 31 | end |
22 | 32 | ||
33 | |||
34 | do -- 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) | ||
49 | end | ||
50 | |||
51 | |||
23 | -- testing ipairs | 52 | -- testing ipairs |
24 | local x = 0 | 53 | local x = 0 |
25 | for k,v in ipairs{10,20,30;x=12} do | 54 | for k,v in ipairs{10,20,30;x=12} do |
@@ -65,15 +94,6 @@ local function mp2 (n) -- minimum power of 2 >= n | |||
65 | end | 94 | end |
66 | 95 | ||
67 | 96 | ||
68 | local 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 | ||
74 | end | ||
75 | |||
76 | |||
77 | -- testing C library sizes | 97 | -- testing C library sizes |
78 | do | 98 | do |
79 | local s = 0 | 99 | local s = 0 |