rubyx/test/soml/fragments/test_functions.rb

66 lines
817 B
Ruby
Raw Normal View History

require_relative 'helper'
class TestFunctions < MiniTest::Test
include Fragments
2014-05-28 13:27:18 +02:00
def test_functions
@string_input = <<HERE
2015-11-30 15:20:39 +01:00
class Space
2015-09-20 15:30:07 +02:00
int times(int a, int b)
if_zero( b + 0)
a = 0
else
2015-10-27 10:00:48 +01:00
int m = b - 1
int t = times(a, m)
2015-10-27 10:00:48 +01:00
a = a + t
end
2015-10-27 10:00:48 +01:00
return a
end
int t_seven()
2015-11-05 16:00:41 +01:00
int tim = times(8,10)
tim.putint()
2015-11-05 16:00:41 +01:00
return tim
end
2014-06-07 22:22:32 +02:00
int main()
2015-10-27 10:00:48 +01:00
return t_seven()
end
end
HERE
@length = 505
check 80
end
2015-11-06 23:13:57 +01:00
def test_class_method
@string_input = <<HERE
2015-11-30 15:20:39 +01:00
class Space
2015-11-06 23:13:57 +01:00
int self.some()
return 5
end
int main()
return Object.some()
end
end
HERE
@length = 33
check 5
2015-11-06 23:13:57 +01:00
end
def test_class_method_fails
@string_input = <<HERE
2015-11-30 15:20:39 +01:00
class Space
2015-11-06 23:13:57 +01:00
int main()
return Object.som()
end
end
HERE
assert_raises {check}
end
end