diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/array.lua | 2 | ||||
-rw-r--r-- | test/dump.lua (renamed from test/dump) | 12 | ||||
-rw-r--r-- | test/long.lua (renamed from test/teste.lua) | 2 | ||||
-rw-r--r-- | test/save.lua | 14 | ||||
-rw-r--r-- | test/sort.lua | 2 | ||||
-rw-r--r-- | test/sort/q.lua | 51 | ||||
-rw-r--r-- | test/sort/sort.lua | 51 | ||||
-rw-r--r-- | test/type.lua | 10 |
8 files changed, 21 insertions, 123 deletions
diff --git a/test/array.lua b/test/array.lua index 349fb818..7caca888 100644 --- a/test/array.lua +++ b/test/array.lua @@ -1,6 +1,6 @@ $debug -a = @() +a = {} i=0 while i<10 do diff --git a/test/dump b/test/dump.lua index d5feb2b4..fa0aa4fb 100644 --- a/test/dump +++ b/test/dump.lua @@ -1,20 +1,20 @@ function savevar (n,v) - if v = nil then return end; - if type(v) = "number" then print(n.."="..v) return end - if type(v) = "string" then print(n.."='"..v.."'") return end - if type(v) = "table" then + if v == nil then return end; + if type(v) == "number" then print(n.."="..v) return end + if type(v) == "string" then print(n.."='"..v.."'") return end + if type(v) == "table" then if v.__visited__ ~= nil then print(n .. "=" .. v.__visited__); else - print(n.."=@()") + print(n.."={}") v.__visited__ = n; local r,f; r,f = next(v,nil); while r ~= nil do if r ~= "__visited__" then - if type(r) = 'string' then + if type(r) == 'string' then savevar(n.."."..r,f) else savevar(n.."["..r.."]",f) diff --git a/test/teste.lua b/test/long.lua index 467ce122..5492fd50 100644 --- a/test/teste.lua +++ b/test/long.lua @@ -12,7 +12,7 @@ function sort(a,n) -- selection sort end -v = @(5000) +v = { } i=1 while i <= 5000 do v[i] = 5000-i i=i+1 end diff --git a/test/save.lua b/test/save.lua index 3eb91086..8c64c568 100644 --- a/test/save.lua +++ b/test/save.lua @@ -1,10 +1,10 @@ function savevar (n,v) - if v = nil then return end; - if type(v) = "number" then print(n.."="..v) return end - if type(v) = "string" then print(n.."='"..v.."'") return end - if type(v) = "table" then + if v == nil then return end; + if type(v) == "number" then print(n.."="..v) return end + if type(v) == "string" then print(n.."='"..v.."'") return end + if type(v) == "table" then if v.__visited__ ~= nil then print(n .. "=" .. v.__visited__); else @@ -14,7 +14,7 @@ function savevar (n,v) r,f = next(v,nil); while r ~= nil do if r ~= "__visited__" then - if type(r) = 'string' then + if type(r) == 'string' then savevar(n.."['"..r.."']",f) else savevar(n.."["..r.."]",f) @@ -36,9 +36,9 @@ local n,v end a = 3 -x = @{a = 4, b = "name", l=@[4,5,67]} +x = {a = 4, b = "name", l={4,5,67}} -b = @{t=5} +b = {t=5} x.next = b diff --git a/test/sort.lua b/test/sort.lua index 6d0d9a0d..14d4cf22 100644 --- a/test/sort.lua +++ b/test/sort.lua @@ -31,7 +31,7 @@ function sort(a,n) -- selection sort end function main() - x=@() + x={} n=-1 n=n+1; x[n]="a" n=n+1; x[n]="waldemar" diff --git a/test/sort/q.lua b/test/sort/q.lua deleted file mode 100644 index 8d9a20d4..00000000 --- a/test/sort/q.lua +++ /dev/null @@ -1,51 +0,0 @@ -function quicksort(r,s) - if s<=r then return end -- caso basico da recursao - local v=x[r] - local i=r - local j=s+1 - repeat - repeat i=i+1 until x[i]>=v - repeat j=j-1 until x[j]<=v - x[i],x[j]=x[j],x[i] - until j<=i -- separacao - x[i],x[j]=x[j],x[i] -- undo last swap - x[j],x[r]=x[r],x[j] - quicksort(r,j-1) -- recursao - quicksort(j+1,s) -end - -function main() - x=@() - n=-1 - n=n+1; x[n]="a" - n=n+1; x[n]="waldemar" - n=n+1; x[n]="luiz" - n=n+1; x[n]="lula" - n=n+1; x[n]="peter" - n=n+1; x[n]="raquel" - n=n+1; x[n]="camilo" - n=n+1; x[n]="andre" - n=n+1; x[n]="marcelo" - n=n+1; x[n]="sedrez" - n=n+1; x[n]="z" --- sort(x,n) - quicksort(1,n-1) -print(x[0]..","..x[1]..","..x[2]..","..x[3]..","..x[4]..","..x[5]..","..x[6]..","..x[7]..","..x[8]..","..x[9]..","..x[10]) -end - -function sort(a,n) -- selection sort - local i=1 - while i<=n do - local m=i - local j=i+1 - while j<=n do - if a[j]<a[m] then m=j end - j=j+1 - end - a[i],a[m]=a[m],a[i] -- swap a[i] and a[m] - print (i, a[i]) - i=i+1 - end -end - -main() diff --git a/test/sort/sort.lua b/test/sort/sort.lua deleted file mode 100644 index ba2e273c..00000000 --- a/test/sort/sort.lua +++ /dev/null @@ -1,51 +0,0 @@ -$debug -function quicksort(r,s) - if s<=r then return end -- caso basico da recursao - local v=x[r] - local i=r - local j=s+1 - i=i+1; while x[i]<v do i=i+1 end - j=j-1; while x[j]>v do j=j-1 end - x[i],x[j]=x[j],x[i] - while j>i do -- separacao - i=i+1; while x[i]<v do i=i+1 end - j=j+1; while x[j]>v do j=j-1 end - x[i],x[j]=x[j],x[i] - end - x[i],x[j]=x[j],x[i] -- undo last swap - x[j],x[r]=x[r],x[j] - quicksort(r,j-1) -- recursao - quicksort(j+1,s) -end - -function sort(a,n) -- selection sort - local i=1 - while i<=n do - local m=i - local j=i+1 - while j<=n do - if a[j]<a[m] then m=j end - j=j+1 - end - a[i],a[m]=a[m],a[i] -- swap a[i] and a[m] - print (i, a[i]) - i=i+1 - end -end - -x=@(20) -n=-1 -n=n+1; x[n]="a" -n=n+1; x[n]="waldemar" -n=n+1; x[n]="luiz" -n=n+1; x[n]="lula" -n=n+1; x[n]="peter" -n=n+1; x[n]="raquel" -n=n+1; x[n]="camilo" -n=n+1; x[n]="andre" -n=n+1; x[n]="marcelo" -n=n+1; x[n]="sedrez" -n=n+1; x[n]="z" --- sort(x,n) -quicksort(1,n-1) -print(x[0]..","..x[1]..","..x[2]..","..x[3]..","..x[4]..","..x[5]..","..x[6]..","..x[7]..","..x[8]..","..x[9]..","..x[10]) diff --git a/test/type.lua b/test/type.lua index 5078920b..3079391d 100644 --- a/test/type.lua +++ b/test/type.lua @@ -3,7 +3,7 @@ $debug function check (object, class) local v = next(object,nil); while v ~= nil do - if class[v] = nil then + if class[v] == nil then print("unknown field: " .. v) elseif type(object[v]) ~= class[v].type then print("wrong type for field " .. v) @@ -12,7 +12,7 @@ function check (object, class) end v = next(class,nil); while v ~= nil do - if object[v] = nil then + if object[v] == nil then if class[v].default ~= nil then object[v] = class[v].default else @@ -23,9 +23,9 @@ function check (object, class) end end -typeblock = @{x = @{default = 0, type = "number"}, - y = @{default = 0, type = "number"}, - name = @{type = "string"} +typeblock = {x = {default = 0, type = "number"}, + y = {default = 0, type = "number"}, + name = {type = "string"} } function block(t) check(t,typeblock) end |