2018-04-19 18:59:48 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
module Builtin
|
|
|
|
class SimpleInt < BuiltinTest
|
|
|
|
|
|
|
|
def test_add
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "5 + 5"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal Parfait::Integer , get_return.class
|
|
|
|
assert_equal 10 , get_return.value
|
|
|
|
end
|
|
|
|
def test_minus
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "5 - 5"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal 0 , get_return.value
|
|
|
|
end
|
|
|
|
def test_minus_neg
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "5 - 15"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal -10 , get_return.value
|
|
|
|
end
|
2018-04-20 09:27:06 +02:00
|
|
|
def test_rshift
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "#{2**8} >> 3"
|
2018-04-20 09:27:06 +02:00
|
|
|
assert_equal 2**5 , get_return.value
|
|
|
|
end
|
|
|
|
def test_lshift
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "#{2**8} << 3"
|
2018-04-20 09:27:06 +02:00
|
|
|
assert_equal 2**11 , get_return.value
|
|
|
|
end
|
2018-04-19 18:59:48 +02:00
|
|
|
def test_div10
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "45.div10"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal 4 , get_return.value
|
|
|
|
end
|
|
|
|
def test_div4
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "45.div4"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal 11 , get_return.value
|
|
|
|
end
|
|
|
|
def test_mult
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "4 * 4"
|
2018-04-19 18:59:48 +02:00
|
|
|
assert_equal 16 , get_return.value
|
|
|
|
end
|
2018-04-19 21:57:31 +02:00
|
|
|
def test_smaller_true
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "4 < 5"
|
2018-04-19 21:41:40 +02:00
|
|
|
assert_equal Parfait::TrueClass , get_return.class
|
2018-04-19 21:13:52 +02:00
|
|
|
end
|
2018-04-19 21:57:31 +02:00
|
|
|
def test_smaller_false
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "6 < 5"
|
2018-04-19 21:57:31 +02:00
|
|
|
assert_equal Parfait::FalseClass , get_return.class
|
|
|
|
end
|
|
|
|
def test_larger_true
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "5 > 4"
|
2018-04-19 21:57:31 +02:00
|
|
|
assert_equal Parfait::TrueClass , get_return.class
|
|
|
|
end
|
|
|
|
def test_larger_false
|
2018-04-23 13:05:37 +02:00
|
|
|
run_input "5 > 6"
|
2018-04-19 21:57:31 +02:00
|
|
|
assert_equal Parfait::FalseClass , get_return.class
|
|
|
|
end
|
2018-04-19 18:59:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|