Commit | Line | Data |
98478aff |
1 | #!perl |
2 | use strict; |
3 | use warnings FATAL => 'all'; |
4 | use Test::More; |
5 | |
6 | BEGIN { |
7 | if (!eval { require 5.016; 1 }) { |
8 | plan skip_all => "This test requires 5.16"; |
9 | } |
10 | } |
11 | |
12 | use 5.016; |
13 | |
14 | use Function::Parameters; |
15 | |
16 | fun fact ($n) { |
17 | if ($n < 2) { |
18 | return 1; |
19 | } |
20 | return $n * __SUB__->($n - 1); |
21 | } |
22 | |
23 | is(fact(5), 120); |
24 | |
25 | is(fun ($n = 8) { $n < 2 ? 1 : $n * __SUB__->($n - 1) }->(), 40320); |
26 | |
27 | fun fact2 ($n) { |
28 | if ($n < 2) { |
29 | return 1; |
30 | } |
31 | return $n * fact2($n - 1); |
32 | } |
33 | |
34 | is(fact2(5), 120); |
35 | |
36 | done_testing; |