Skip to content

Commit

Permalink
issue #198 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Nov 8, 2020
1 parent 5a0c360 commit 86c2020
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/comptests/23_arith2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,28 @@ assert(doit and type(doit) == 'function')
assert(math.abs(doit(11.1, 'add') - 16.1) < 1e-15)
assert(math.abs(doit(1.1, 'mul') - 5.5) < 1e-15)
assert(math.abs(doit(5.5, 'sub') - 0.5) < 1e-15)
assert(math.abs(doit(5.5, 'div') - 1.1) < 1e-15)
assert(math.abs(doit(5.5, 'div') - 1.1) < 1e-15)

f = compiler.load([[
function doit(a: number, what)
if what == 'add' then
return 5+a
elseif what == 'sub' then
return 5-a
elseif what == 'mul' then
return 5*a
elseif what == 'div' then
return 5/a
else
return 0
end
end
]]
)
assert(f and type(f) == 'function')
f()
assert(doit and type(doit) == 'function')
assert(math.abs(doit(11.1, 'add') - 16.1) < 1e-15)
assert(math.abs(doit(1.1, 'mul') - 5.5) < 1e-15)
assert(math.abs(doit(5.5, 'sub') + 0.5) < 1e-15)
assert(math.abs(doit(2.5, 'div') - 2.0) < 1e-15)

0 comments on commit 86c2020

Please sign in to comment.