Added NLetterWords Goodie

master
Dylan Lloyd 2012-04-16 01:58:41 -04:00
parent 6dd856e8ed
commit 543ec98443
4 changed files with 64064 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package DDG::Goodie::NLetterWords;
use DDG::Goodie;
triggers end => "words", "word";
zci is_cached => 1;
handle query_parts => sub {
return unless /^([0-9]{1,50}) (letter|char|character) words?$/;
my $length = $1;
my @allwords = share('words.txt')->slurp;
my @words;
foreach (@allwords) {
chomp($_);
if (length($_) == $length) { push(@words, $_); }
}
return unless scalar(@words) >= 1;
my $output = "$length letter words: ";
foreach (@words) {
$output = $output . $_ . ", ";
}
chop($output);
chop($output);
return $output;
};
1;

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ ddg_goodie_test(
DDG::Goodie::GUID
DDG::Goodie::GoldenRatio
DDG::Goodie::HTMLEntities
DDG::Goodie::NLetterWords
DDG::Goodie::Passphrase
DDG::Goodie::PercentError
DDG::Goodie::Perimeter
@ -85,6 +86,11 @@ ddg_goodie_test(
'&#x21' => test_zci("Decoded HTML Entity: !, decimal: 33, hexadecimal: 0021", html => "Decoded HTML Entity: !, decimal: 33, hexadecimal: <a href=\"/?q=U%2B0021\">0021</a>", answer_type => 'html_entity', is_cached => 1),
'html entity &amp;' => test_zci("Decoded HTML Entity: &, decimal: 38, hexadecimal: 0026", html => "Decoded HTML Entity: &, decimal: 38, hexadecimal: <a href=\"/?q=U%2B0026\">0026</a>", answer_type => 'html_entity', is_cached => 1),
# NLetterWords
'1 letter words' => test_zci('1 letter words: a, I', answer_type => 'nletterwords', is_cached => 1),
'1 char words' => test_zci('1 letter words: a, I', answer_type => 'nletterwords', is_cached => 1),
'1 character words' => test_zci('1 letter words: a, I', answer_type => 'nletterwords', is_cached => 1),
# Passphrase
'passphrase 4 words' => test_zci(qr/random passphrase:/, answer_type => 'passphrase', is_cached => 0),

20
t/NLetterWords.t Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'nletterwords';
zci is_cached => 1;
ddg_goodie_test(
[qw(
DDG::Goodie::NLetterWords
)],
'1 letter words' => test_zci('1 letter words: a, I'),
'1 char words' => test_zci('1 letter words: a, I'),
'1 character words' => test_zci('1 letter words: a, I'),
);
done_testing;