diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-21 16:50:34 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-21 16:50:34 -0400 |
commit | 597610ad1c915a5b004148fdb3151b0cec976790 (patch) | |
tree | 9e3e002a3b536ea943d73b51c8318d08f3f6ecb9 /t/fun/recursion.t | |
parent | 336e491e532144d1c8a6e367409149e8d084fa1d (diff) | |
download | parse-keyword-597610ad1c915a5b004148fdb3151b0cec976790.tar.gz parse-keyword-597610ad1c915a5b004148fdb3151b0cec976790.zip |
add tests for Fun
Diffstat (limited to 't/fun/recursion.t')
-rw-r--r-- | t/fun/recursion.t | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/t/fun/recursion.t b/t/fun/recursion.t new file mode 100644 index 0000000..75663ec --- /dev/null +++ b/t/fun/recursion.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use lib 't/fun/lib'; + +BEGIN { + if (!eval { require 5.016; 1 }) { + plan skip_all => "This test requires 5.16"; + } +} + +use 5.016; + +use Fun; + +fun fact ($n) { + if ($n < 2) { + return 1; + } + return $n * __SUB__->($n - 1); +} + +is(fact(5), 120); + +is(fun ($n = 8) { $n < 2 ? 1 : $n * __SUB__->($n - 1) }->(), 40320); + +fun fact2 ($n) { + if ($n < 2) { + return 1; + } + return $n * fact2($n - 1); +} + +is(fact2(5), 120); + +done_testing; |