diff --git a/ext/equations-parser b/ext/equations-parser index 7428a00..ec64e60 160000 --- a/ext/equations-parser +++ b/ext/equations-parser @@ -1 +1 @@ -Subproject commit 7428a00a7e56f14afc9178de599e331bae71d17b +Subproject commit ec64e60b8cd11299c2237b13630801f79a1954c1 diff --git a/ext/libnativemath/extconf.rb b/ext/libnativemath/extconf.rb index b0973e1..e43b45c 100644 --- a/ext/libnativemath/extconf.rb +++ b/ext/libnativemath/extconf.rb @@ -38,7 +38,7 @@ end GIT_REPOSITORY = 'https://github.com/oxeanbits/equations-parser.git'.freeze -COMMIT = '7428a00a7e56f14afc9178de599e331bae71d17b'.freeze +COMMIT = 'ec64e60b8cd11299c2237b13630801f79a1954c1'.freeze Dir.chdir(BASEDIR) do system('git init') diff --git a/test/test_parsec.rb b/test/test_parsec.rb index 3c337c5..a839351 100644 --- a/test/test_parsec.rb +++ b/test/test_parsec.rb @@ -38,6 +38,22 @@ def test_complex_math_equations assert_equal(4.56, parser.eval_equation('round_decimal(4.559, 2)')) end + def test_round_with_optional_direction + parser = Parsec::Parsec + + assert_equal(10, parser.eval_equation('round(10.1)')) + assert_equal(11, parser.eval_equation('round(10.1, "up")')) + assert_equal(10, parser.eval_equation('round(10.9, "down")')) + assert_equal(-10, parser.eval_equation('round(-10.9, "up")')) + assert_equal(-11, parser.eval_equation('round(-10.1, "down")')) + + assert_equal(4.63, parser.eval_equation('round_decimal(4.621, 2, "up")')) + assert_equal(4.62, parser.eval_equation('round_decimal(4.629, 2, "down")')) + + assert_raises(SyntaxError) { parser.eval_equation('round(10.5, "invalid")') } + assert_raises(SyntaxError) { parser.eval_equation('round(10.5, "up", "extra")') } + end + def test_if_then_else_equations parser = Parsec::Parsec assert_equal('bigger', parser.eval_equation('4 > 2 ? "bigger" : "smaller"'))