From 16c629c7381f8616f62f4c9b50952060934de0f2 Mon Sep 17 00:00:00 2001 From: Koosha Khajeh Moogahi Date: Thu, 24 Jan 2013 12:50:34 +0330 Subject: [PATCH] Make the output of Fibonacci verbose --- lib/DDG/Goodie/Fibonacci.pm | 5 ++++- t/Fibonacci.pm | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/DDG/Goodie/Fibonacci.pm b/lib/DDG/Goodie/Fibonacci.pm index 90bf7215c..6849dd86f 100644 --- a/lib/DDG/Goodie/Fibonacci.pm +++ b/lib/DDG/Goodie/Fibonacci.pm @@ -3,6 +3,7 @@ package DDG::Goodie::Fibonacci; use strict; use DDG::Goodie; +use Lingua::EN::Numbers::Ordinate qw(ordsuf); triggers any => 'fib', 'fibonacci'; zci is_cached => 1; @@ -29,7 +30,9 @@ handle remainder => sub { for my $i (2..$#fib) { $fib[$i] = $fib[$i - 1] + $fib[$i - 2]; } - return "fib($_) = ${fib[$_]} with f(0) = 0"; + my $suf = ordsuf($_); + return "The $_$suf fibonacci number is ${fib[$_]} (assuming f(0) = 0).", + html => "The $_$suf fibonacci number is ${fib[$_]} (assuming f(0) = 0)."; }; 1; diff --git a/t/Fibonacci.pm b/t/Fibonacci.pm index 00e5fbd7d..84a24e77a 100644 --- a/t/Fibonacci.pm +++ b/t/Fibonacci.pm @@ -7,8 +7,10 @@ zci is_cached => 1; ddg_goodie_test( [qw(DDG::Goodie::Fibonacci)], - 'fib 7' => test_zci('fib(7) = 13 with f(0) = 0'), - 'fibonacci 33' => test_zci('fib(33) = 3524578 with f(0) = 0'), + 'fib 7' => test_zci('The 7th fibonacci number is 13 (assuming f(0) = 0).', + html => 'The 7th fibonacci number is 13 (assuming f(0) = 0).'), + 'fibonacci 33' => test_zci('The 33rd fibonacci number is 3524578 (assuming f(0) = 0).', + html => 'The 33rd fibonacci number is 3524578 (assuming f(0) = 0).'), ); done_testing;