adds a runner that parses files (and some fibo examples)
This commit is contained in:
parent
f0ccdfcb65
commit
0a3253c5c3
6
test/runners/fibo_recursice.cr
Normal file
6
test/runners/fibo_recursice.cr
Normal 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 )
|
9
test/runners/fibo_times.cr
Normal file
9
test/runners/fibo_times.cr
Normal 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
31
test/test_runner.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user