mod and div for int

This commit is contained in:
Torsten Ruger 2015-11-11 20:36:40 +02:00
parent 1e7935bf85
commit 351a747bfd
2 changed files with 37 additions and 22 deletions

View File

@ -34,4 +34,15 @@ class Integer < Value
str.putstring() str.putstring()
return self return self
end 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 end

View File

@ -3,52 +3,56 @@ require_relative 'helper'
class TestPutiRT < MiniTest::Test class TestPutiRT < MiniTest::Test
include RuntimeTests 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 def test_as_char1
@string_input = <<HERE @string_input = "return 5.as_char()"
return 5.as_char()
HERE
check_return 53 check_return 53
end end
def test_as_char2 def test_as_char2
@string_input = <<HERE @string_input = "return 10.as_char()"
return 10.as_char()
HERE
check_return 32 check_return 32
end end
def test_tos_one_digit def test_tos_one_digit
@string_input = <<HERE @string_input = "Word five = 5.to_s()
Word five = 5.to_s() five.putstring()"
five.putstring()
HERE
@stdout = " 5" @stdout = " 5"
check check
end end
def test_tos_zero def test_tos_zero
@string_input = <<HERE @string_input = "Word five = 0.to_s()
Word five = 0.to_s() five.putstring()"
five.putstring()
HERE
@stdout = " 0" @stdout = " 0"
check check
end end
def test_tos_two_digit def test_tos_two_digit
@string_input = <<HERE @string_input = "Word five = 15.to_s()
Word five = 15.to_s() five.putstring()"
five.putstring()
HERE
@stdout = " 15" @stdout = " 15"
check check
end end
def test_tos_three_digit def test_tos_three_digit
@string_input = <<HERE @string_input = "Word five = 150.to_s()
Word five = 150.to_s() five.putstring()"
five.putstring()
HERE
@stdout = " 150" @stdout = " 150"
check check
end end