Skip to content

Commit 97a478f

Browse files
Maxime Chevalier-Boisvertk0kubun
authored andcommitted
Add recursive factorial and fibonacci functions to test_zjit.rb
1 parent 102c48c commit 97a478f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,31 @@ def test(n)
348348
}
349349
end
350350

351+
def test_recursive_fact
352+
assert_compiles '[1, 6, 720]', %q{
353+
def fact(n)
354+
if n == 0
355+
return 1
356+
end
357+
return n * fact(n-1)
358+
end
359+
[fact(0), fact(3), fact(6)]
360+
}
361+
end
362+
363+
# FIXME: currently produces the wrong value
364+
#def test_recursive_fib
365+
# assert_compiles '[0, 2, 3]', %q{
366+
# def fib(n)
367+
# if n < 2
368+
# return n
369+
# end
370+
# return fib(n-1) + fib(n-2)
371+
# end
372+
# [fib(0), fib(3), fib(4)]
373+
# }
374+
#end
375+
351376
private
352377

353378
# Assert that every method call in `test_script` can be compiled by ZJIT

0 commit comments

Comments
 (0)