rubyx/test/risc/builtin/test_int_math.rb

43 lines
982 B
Ruby
Raw Normal View History

require_relative "helper"
module Risc
module Builtin
2018-04-24 18:45:58 +02:00
class IntMath < BuiltinTest
def test_add
2018-04-24 19:12:49 +02:00
run_main "5 + 5"
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
def test_minus
2018-04-24 19:12:49 +02:00
run_main "5 - 5"
assert_equal 0 , get_return.value
end
def test_minus_neg
2018-04-24 19:12:49 +02:00
run_main "5 - 15"
assert_equal -10 , get_return.value
end
2018-04-20 09:27:06 +02:00
def test_rshift
2018-04-24 19:12:49 +02:00
run_main "#{2**8} >> 3"
2018-04-20 09:27:06 +02:00
assert_equal 2**5 , get_return.value
end
def test_lshift
2018-04-24 19:12:49 +02:00
run_main "#{2**8} << 3"
2018-04-20 09:27:06 +02:00
assert_equal 2**11 , get_return.value
end
def test_div10
2018-04-24 19:12:49 +02:00
run_main "45.div10"
assert_equal 4 , get_return.value
end
def test_div4
2018-04-24 19:12:49 +02:00
run_main "45.div4"
assert_equal 11 , get_return.value
end
def test_mult
2018-04-24 19:12:49 +02:00
run_main "4 * 4"
assert_equal 16 , get_return.value
end
end
end
end