rubyx/test/risc/mains/test_adds.rb

49 lines
948 B
Ruby
Raw Normal View History

2018-04-26 11:33:19 +02:00
require_relative 'helper'
2018-04-23 13:05:37 +02:00
module Mains
2018-04-26 11:33:19 +02:00
class TestAdds < MainsTest
2018-04-23 13:05:37 +02:00
def test_ruby_adds
2018-04-24 19:12:49 +02:00
run_main <<HERE
2018-04-23 13:05:37 +02:00
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-24 19:12:49 +02:00
run_main <<HERE
2018-04-23 13:05:37 +02:00
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
2018-04-24 19:12:49 +02:00
run_main <<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