extract the ruby from mains tests
move up in directory in preparation for arm tests
This commit is contained in:
5
test/mains/README.md
Normal file
5
test/mains/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Method testing
|
||||
|
||||
Test Whole methods by their output. Using the main method (implicitly)
|
||||
|
||||
Through Interpreter
|
7
test/mains/adds.rb
Normal file
7
test/mains/adds.rb
Normal file
@ -0,0 +1,7 @@
|
||||
a = 0
|
||||
b = 20
|
||||
while( a < b )
|
||||
a = a + 1
|
||||
b = b - 1
|
||||
end
|
||||
return a
|
11
test/mains/fibo.rb
Normal file
11
test/mains/fibo.rb
Normal file
@ -0,0 +1,11 @@
|
||||
n = 6
|
||||
a = 0
|
||||
b = 1
|
||||
i = 1
|
||||
while( i < n )
|
||||
result = a + b
|
||||
a = b
|
||||
b = result
|
||||
i = i + 1
|
||||
end
|
||||
return result
|
13
test/mains/helper.rb
Normal file
13
test/mains/helper.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Mains
|
||||
class MainsTest < MiniTest::Test
|
||||
include Risc::Ticker
|
||||
def setup;end
|
||||
|
||||
def run_main_file(file)
|
||||
input = File.read("test/mains/#{file}.rb")
|
||||
run_main(input)
|
||||
end
|
||||
end
|
||||
end
|
5
test/mains/subs.rb
Normal file
5
test/mains/subs.rb
Normal file
@ -0,0 +1,5 @@
|
||||
b = 10
|
||||
while( b >= 1 )
|
||||
b = b - 1
|
||||
end
|
||||
return b
|
19
test/mains/test_adds.rb
Normal file
19
test/mains/test_adds.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Mains
|
||||
class TestAdds < MainsTest
|
||||
|
||||
def test_ruby_adds
|
||||
run_main_file "adds"
|
||||
assert_equal 10 , get_return
|
||||
end
|
||||
def test_ruby_subs
|
||||
run_main_file "subs"
|
||||
assert_equal 0 , get_return
|
||||
end
|
||||
def test_ruby_adds_fibo
|
||||
run_main_file "fibo"
|
||||
assert_equal 8 , get_return
|
||||
end
|
||||
end
|
||||
end
|
13
test/mains/test_puts.rb
Normal file
13
test/mains/test_puts.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Mains
|
||||
class TestPuts < MainsTest
|
||||
|
||||
def test_say_hi
|
||||
hi = "Hello there"
|
||||
run_main_return "'#{hi}'.putstring"
|
||||
assert_equal hi.length , get_return
|
||||
assert_equal hi , @interpreter.stdout
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user