From 9083492dcbc9affeb0a07560d35d6f53642421ca Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Mon, 28 Dec 2020 21:09:08 +0000 Subject: [PATCH] issue #198 Add a test --- tests/comptests/inputs/24_arith.lua | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/comptests/inputs/24_arith.lua diff --git a/tests/comptests/inputs/24_arith.lua b/tests/comptests/inputs/24_arith.lua new file mode 100644 index 0000000..66ee1b3 --- /dev/null +++ b/tests/comptests/inputs/24_arith.lua @@ -0,0 +1,48 @@ +f = compiler.load([[ +function doit(a, what) + if what == 'add' then + return a+5 + elseif what == 'sub' then + return a-5 + elseif what == 'mul' then + return a*5 + elseif what == 'div' then + return a/5 + 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(5.5, 'div') - 1.1) < 1e-15) + +f = compiler.load([[ +function doit(a, 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) +print 'Ok' \ No newline at end of file