diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/nextvar.lua | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index 00e509f8..d1da3cee 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
@@ -316,21 +316,6 @@ end | |||
316 | local a = {} | 316 | local a = {} |
317 | for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end | 317 | for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end |
318 | 318 | ||
319 | |||
320 | -- Table length with limit smaller than maximum value at array | ||
321 | local a = {} | ||
322 | for i = 1,64 do a[i] = true end -- make its array size 64 | ||
323 | for i = 1,64 do a[i] = nil end -- erase all elements | ||
324 | assert(T.querytab(a) == 64) -- array part has 64 elements | ||
325 | a[32] = true; a[48] = true; -- binary search will find these ones | ||
326 | a[51] = true -- binary search will miss this one | ||
327 | assert(#a == 48) -- this will set the limit | ||
328 | assert(select(3, T.querytab(a)) == 48) -- this is the limit now | ||
329 | a[50] = true -- this will set a new limit | ||
330 | assert(select(3, T.querytab(a)) == 50) -- this is the limit now | ||
331 | -- but the size is larger (and still inside the array part) | ||
332 | assert(#a == 51) | ||
333 | |||
334 | end --] | 319 | end --] |
335 | 320 | ||
336 | 321 | ||
@@ -344,6 +329,20 @@ assert(#{1, 2, 3, nil, nil} == 3) | |||
344 | print'+' | 329 | print'+' |
345 | 330 | ||
346 | 331 | ||
332 | do | ||
333 | local s1, s2 = math.randomseed() | ||
334 | print(string.format( | ||
335 | "testing length for some random tables (seeds 0X%x:%x)", s1, s2)) | ||
336 | local N = 130 | ||
337 | for i = 1, 1e3 do -- create that many random tables | ||
338 | local a = table.create(math.random(N)) -- initiate with random size | ||
339 | for j = 1, math.random(N) do -- add random number of random entries | ||
340 | a[math.random(N)] = true | ||
341 | end | ||
342 | assert(#a == 0 or a[#a] and not a[#a + 1]) | ||
343 | end | ||
344 | end | ||
345 | |||
347 | local nofind = {} | 346 | local nofind = {} |
348 | 347 | ||
349 | a,b,c = 1,2,3 | 348 | a,b,c = 1,2,3 |