diff --git a/lib/soml/parfait/integer.soml b/lib/soml/parfait/integer.soml index 19443679..80a34c1a 100644 --- a/lib/soml/parfait/integer.soml +++ b/lib/soml/parfait/integer.soml @@ -34,4 +34,15 @@ class Integer < Value str.putstring() return self end + + int div( Integer by) + int ret = self / by + return ret + end + + int mod(Integer by) + int base = self / by + base = base * by + return self - base + end end diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb index 774256d6..09ea6423 100644 --- a/test/parfait/test_integer.rb +++ b/test/parfait/test_integer.rb @@ -3,52 +3,56 @@ require_relative 'helper' class TestPutiRT < MiniTest::Test include RuntimeTests + def test_mod + @string_input = "return 5.mod(3)" + check_return 2 + end + def test_mod2 + @string_input = "return 2.mod(4)" + check_return 2 + end + def test_mod3 + @string_input = "return 2.mod(4)" + check_return 2 + end + def test_div + @string_input = "return 5.div(4)" + check_return 1 + end def test_as_char1 - @string_input = <