Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/libnativemath/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions test/test_parsec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"'))
Expand Down