diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/nextvar.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index 5d8796f7..cee77f76 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
| @@ -39,13 +39,32 @@ do -- rehash moving elements from array to hash | |||
| 39 | for i = 5, 95 do a[i] = nil end | 39 | for i = 5, 95 do a[i] = nil end |
| 40 | check(a, 128, 0) | 40 | check(a, 128, 0) |
| 41 | 41 | ||
| 42 | a.x = 1 -- force a re-hash | 42 | a[129] = 1 -- force a re-hash |
| 43 | check(a, 4, 8) | 43 | check(a, 4, 8) -- keys larger than 4 go to the hash part |
| 44 | 44 | ||
| 45 | for i = 1, 4 do assert(a[i] == i) end | 45 | for i = 1, 4 do assert(a[i] == i) end |
| 46 | for i = 5, 95 do assert(a[i] == nil) end | 46 | for i = 5, 95 do assert(a[i] == nil) end |
| 47 | for i = 96, 100 do assert(a[i] == i) end | 47 | for i = 96, 100 do assert(a[i] == i) end |
| 48 | assert(a.x == 1) | 48 | assert(a[129] == 1) |
| 49 | end | ||
| 50 | |||
| 51 | |||
| 52 | do -- growing hash part keeping array part | ||
| 53 | local a = table.create(1000) | ||
| 54 | check(a, 1000, 0) | ||
| 55 | a.x = 10 | ||
| 56 | check(a, 1000, 1) -- array part keeps its elements | ||
| 57 | end | ||
| 58 | |||
| 59 | |||
| 60 | do -- "growing" length of a prebuilt table | ||
| 61 | local N = 100 | ||
| 62 | local a = table.create(N) | ||
| 63 | for i = 1, N do | ||
| 64 | a[#a + 1] = true | ||
| 65 | assert(#a == i) | ||
| 66 | end | ||
| 67 | check(a, N, 0) | ||
| 49 | end | 68 | end |
| 50 | 69 | ||
| 51 | 70 | ||
