RosettaCodeData/Task/Arithmetic-evaluation/Sidef/arithmetic-evaluation-2.sidef

14 lines
570 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

for expr,res in [
['2+3' => 5],
['-4-3' => -7],
['-+2+3/4' => -1.25],
['2*3-4' => 2],
['2*(3+4)+2/4' => 2/4 + 14],
['2*-3--4+-0.25' => -2.25],
['2 * (3 + (4 * 5 + (6 * 7) * 8) - 9) * 10' => 7000],
] { 
var num = evalArithmeticExp(expr)
assert_eq(num, res)
"%-45s == %10g\n".printf(expr, num)
}