Pi: correct parsing for max length (#4441)

* Pi: correct parsing for max length

* small style fix

* fix for pi 1000
master
Philip Kirkbride 2017-08-19 18:21:05 -04:00 committed by Rob Emery
parent b7de67c5bd
commit 171ef55def
2 changed files with 5 additions and 3 deletions

View File

@ -22,12 +22,12 @@ my $PI = '3.14159265358979323846264338327950288419716939937510582097494459230781
'147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216'.
'4201989';
my $PI_max_digits = length($PI);
my $PI_max_digits = length($PI) - 2;
handle query_raw => sub {
return unless $_ =~ /^(?:pi|π)?\s*(?:to|first)?\s*(?<decimal>\d+)\s*(?:(?:decimal|digit)s?)?\s*(?:of\s+(?:pi|π))?$/i &&
$+{decimal} > 0 && $+{decimal} < $PI_max_digits;
$+{decimal} > 0 && $+{decimal} <= $PI_max_digits;
my $answer = substr $PI, 0, ( $1 + 2 );
return $answer, structured_answer => {

4
t/Pi.t
View File

@ -34,7 +34,9 @@ ddg_goodie_test(
'π to 6 digits' => build_test("3.141592", 6),
'pi ff' => undef,
'pi 3f2' => undef
'pi 3f2' => undef,
'pi 1001' => undef,
'pi 1002' => undef,
);
done_testing;