Lua improvements - Mark Gossage patch #1295168
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7476 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b4a56ba679
commit
bf48768e04
5 changed files with 442 additions and 0 deletions
66
Examples/test-suite/lua/li_std_vector_runme.lua
Normal file
66
Examples/test-suite/lua/li_std_vector_runme.lua
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
require("import") -- the import fn
|
||||
import("li_std_vector") -- import code
|
||||
|
||||
for k,v in pairs(li_std_vector) do _G[k]=v end -- move to global
|
||||
|
||||
iv = IntVector(4)
|
||||
for i=0,3 do
|
||||
iv[i] = i
|
||||
end
|
||||
|
||||
for i=0,3 do assert(iv[i]==i) end
|
||||
|
||||
x = average(iv)
|
||||
|
||||
function near(x,y) return math.abs(x-y)<0.001 end
|
||||
|
||||
assert(near(x,1.5))
|
||||
|
||||
rv = RealVector()
|
||||
rv:push_back(10)
|
||||
rv:push_back(10.5)
|
||||
rv:push_back(11)
|
||||
rv:push_back(11.5)
|
||||
|
||||
a=half(rv)
|
||||
for i=0,rv:size()-1 do
|
||||
assert(near(a[i],rv[i]/2))
|
||||
end
|
||||
|
||||
dv = DoubleVector(10)
|
||||
for i=0,9 do dv[i] = i/2.0 end
|
||||
|
||||
halve_in_place(dv)
|
||||
|
||||
for i=0,9 do
|
||||
assert(near(dv[i],i/4))
|
||||
end
|
||||
|
||||
sv=StructVector(4)
|
||||
|
||||
for i=0,3 do
|
||||
sv[i]=Struct(i)
|
||||
end
|
||||
|
||||
for i=0,3 do
|
||||
assert( swig_type(sv[i]) =='_p_Struct' and sv[i].num==i)
|
||||
end
|
||||
|
||||
-- range checking
|
||||
idx=0
|
||||
function test_set() iv[idx]=0 end
|
||||
function test_get() iv[idx]=0 end
|
||||
|
||||
idx=0 --ok
|
||||
assert(pcall(test_get)==true)
|
||||
assert(pcall(test_set)==true)
|
||||
idx=-1 --should error
|
||||
assert(pcall(test_get)==false)
|
||||
assert(pcall(test_set)==false)
|
||||
idx=3 --ok
|
||||
assert(pcall(test_get)==true)
|
||||
assert(pcall(test_set)==true)
|
||||
idx=4 --should error
|
||||
assert(pcall(test_get)==false)
|
||||
assert(pcall(test_set)==false)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue