adds a runner that parses files (and some fibo examples)

This commit is contained in:
Torsten Ruger 2014-04-28 11:19:28 +03:00
parent f0ccdfcb65
commit 0a3253c5c3
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,6 @@
def fibonacci_r( n )
return n if n <= 1
fibonacci_r( n - 1 ) + fibonacci_r( n - 2 )
end
puts fibonacci( 10 )

View File

@ -0,0 +1,9 @@
def fibonacci_t(n)
a,b = 0,1
n.times do
printf("%d\n", a)
a,b = b,a+b
end
end
puts fibonacci_t( 10 )

31
test/test_runner.rb Normal file
View File

@ -0,0 +1,31 @@
require_relative 'helper'
class TestRunner < MiniTest::Test
# this creates test methods dynamically , one for each file in runners directory
def self.runnable_methods
methods = []
Dir[File.join(File.dirname(__FILE__) , "runners" , "*.cr")].each do |file|
meth = File.basename(file).split(".").first
name = "test_#{meth}"
methods << name
self.send(:define_method, name ) {
execute file
}
end
methods
end
def execute file
string = File.read(file)
syntax = Parser::Composed.new.parse(string)
tree = Parser::Transform.new.apply(syntax)
#transform
# write
#link
# execute
# check result ?
puts tree.inspect
end
end