rubyx/test/risc/mains/test_adds.rb

51 lines
1009 B
Ruby
Raw Normal View History

2018-04-23 13:05:37 +02:00
require_relative '../helper'
module Mains
class TestLargerWhile < MiniTest::Test
include Risc::Ticker
def setup;end
def test_ruby_adds
run_input <<HERE
a = 0
b = 20
while( a < b )
a = a + 1
b = b - 1
end
return a
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
2018-04-24 18:57:14 +02:00
def test_ruby_subs
2018-04-23 13:05:37 +02:00
run_input <<HERE
b = 10
2018-04-24 18:57:14 +02:00
while( b >= 1 )
2018-04-23 13:05:37 +02:00
b = b - 1
end
return b
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 0 , get_return.value
end
def test_ruby_adds_fibo
run_input <<HERE
2018-04-24 18:57:14 +02:00
n = 6
2018-04-23 13:05:37 +02:00
a = 0
b = 1
i = 1
while( i < n )
result = a + b
a = b
b = result
i = i + 1
end
return result
HERE
assert_equal Parfait::Integer , get_return.class
2018-04-24 18:57:14 +02:00
assert_equal 8 , get_return.value
2018-04-23 13:05:37 +02:00
end
end
end