Refactor math support to provide more consistent and complete math library coverage
This commit is contained in:
@@ -2,17 +2,26 @@ package.path = "?.lua;src/test/errors/?.lua"
|
||||
require 'args'
|
||||
|
||||
-- arg type tests for math library functions
|
||||
local somenumber = {23,45.67,'-12','-345.678'}
|
||||
local somenumber = {1,0.75,'-1','-0.25'}
|
||||
local somepositive = {1,0.75,'2', '2.5'}
|
||||
local notanumber = {nil,astring,aboolean,afunction,atable,athread}
|
||||
local nonnumber = {astring,aboolean,afunction,atable}
|
||||
|
||||
local singleargfunctions = {
|
||||
'abs', 'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'deg', 'exp', 'floor', 'frexp',
|
||||
'log', 'log10', 'rad', 'randomseed', 'sin', 'sinh', 'sqrt', 'tan', 'tanh',
|
||||
}
|
||||
|
||||
'abs', 'acos', 'asin', 'atan', 'ceil', 'cos', 'cosh', 'deg', 'exp', 'floor',
|
||||
'rad', 'randomseed', 'sin', 'sinh', 'tan', 'tanh', 'frexp',
|
||||
}
|
||||
|
||||
local singleargposdomain = {
|
||||
'log', 'log10', 'sqrt',
|
||||
}
|
||||
|
||||
local twoargfunctions = {
|
||||
'atan2', 'fmod', 'pow',
|
||||
'atan2', 'fmod',
|
||||
}
|
||||
|
||||
local twoargsposdomain = {
|
||||
'pow',
|
||||
}
|
||||
|
||||
-- single argument tests
|
||||
@@ -23,6 +32,14 @@ for i,v in ipairs(singleargfunctions) do
|
||||
checkallerrors(funcname,{notanumber},'bad argument #1')
|
||||
end
|
||||
|
||||
-- single argument, positive domain tests
|
||||
for i,v in ipairs(singleargposdomain) do
|
||||
local funcname = 'math.'..v
|
||||
banner(funcname)
|
||||
checkallpass(funcname,{somepositive})
|
||||
checkallerrors(funcname,{notanumber},'bad argument #1')
|
||||
end
|
||||
|
||||
-- two-argument tests
|
||||
for i,v in ipairs(twoargfunctions) do
|
||||
local funcname = 'math.'..v
|
||||
@@ -35,6 +52,18 @@ for i,v in ipairs(twoargfunctions) do
|
||||
checkallerrors(funcname,{somenumber,notanumber},'bad argument #2')
|
||||
end
|
||||
|
||||
-- two-argument, positive domain tests
|
||||
for i,v in ipairs(twoargsposdomain) do
|
||||
local funcname = 'math.'..v
|
||||
banner(funcname)
|
||||
checkallpass(funcname,{somepositive,somenumber})
|
||||
checkallerrors(funcname,{},'bad argument #1')
|
||||
checkallerrors(funcname,{notanumber},'bad argument #1')
|
||||
checkallerrors(funcname,{notanumber,somenumber},'bad argument #1')
|
||||
checkallerrors(funcname,{somenumber},'bad argument #2')
|
||||
checkallerrors(funcname,{somenumber,notanumber},'bad argument #2')
|
||||
end
|
||||
|
||||
-- math.max
|
||||
banner('math.max')
|
||||
checkallpass('math.max',{somenumber})
|
||||
@@ -56,11 +85,10 @@ local somem = {3,4.5,'6.7'}
|
||||
local somen = {8,9.10,'12.34'}
|
||||
local notamn = {astring,aboolean,atable,afunction}
|
||||
banner('math.random')
|
||||
checkallpass('math.random',{})
|
||||
checkallpass('math.random',{somem})
|
||||
checkallpass('math.random',{somem,somen})
|
||||
checkallpass('math.random',{{8},{7.8}})
|
||||
checkallpass('math.random',{{-4,-5.6,'-7','-8.9'},{-1,100,23.45,'-1.23'}})
|
||||
checkallpass('math.random',{},true)
|
||||
checkallpass('math.random',{somem},true)
|
||||
checkallpass('math.random',{somem,somen},true)
|
||||
checkallpass('math.random',{{-4,-5.6,'-7','-8.9'},{-1,100,23.45,'-1.23'}},true)
|
||||
checkallerrors('math.random',{{-4,-5.6,'-7','-8.9'}},'interval is empty')
|
||||
checkallerrors('math.random',{somen,somem},'interval is empty')
|
||||
checkallerrors('math.random',{notamn,somen},'bad argument #1')
|
||||
@@ -71,8 +99,8 @@ local somee = {-3,0,3,9.10,'12.34'}
|
||||
local notae = {nil,astring,aboolean,atable,afunction}
|
||||
banner('math.ldexp')
|
||||
checkallpass('math.ldexp',{somenumber,somee})
|
||||
checkallerrors('math.ldexp',{},'bad argument #2')
|
||||
checkallerrors('math.ldexp',{notanumber},'bad argument #2')
|
||||
checkallerrors('math.ldexp',{},'bad argument')
|
||||
checkallerrors('math.ldexp',{notanumber},'bad argument')
|
||||
checkallerrors('math.ldexp',{notanumber,somee},'bad argument #1')
|
||||
checkallerrors('math.ldexp',{somenumber},'bad argument #2')
|
||||
checkallerrors('math.ldexp',{somenumber,notae},'bad argument #2')
|
||||
Reference in New Issue
Block a user