summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <[email protected]>2025-03-24 16:48:17 -0400
committerTakashi Kokubun <[email protected]>2025-04-18 21:53:01 +0900
commit97a478f95fb09566360bcff2b3fba93098d4e1ac (patch)
treec7485c96a5cde76b6e6ffe17e08a7b2e4bb2a409 /test
parent102c48c85ff3f7dac70b3f12e553e7f035709879 (diff)
Add recursive factorial and fibonacci functions to test_zjit.rb
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_zjit.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index 33fcbe817f..98eae2a58f 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -348,6 +348,31 @@ class TestZJIT < Test::Unit::TestCase
}
end
+ def test_recursive_fact
+ assert_compiles '[1, 6, 720]', %q{
+ def fact(n)
+ if n == 0
+ return 1
+ end
+ return n * fact(n-1)
+ end
+ [fact(0), fact(3), fact(6)]
+ }
+ end
+
+ # FIXME: currently produces the wrong value
+ #def test_recursive_fib
+ # assert_compiles '[0, 2, 3]', %q{
+ # def fib(n)
+ # if n < 2
+ # return n
+ # end
+ # return fib(n-1) + fib(n-2)
+ # end
+ # [fib(0), fib(3), fib(4)]
+ # }
+ #end
+
private
# Assert that every method call in `test_script` can be compiled by ZJIT