Coin: Switching to text template

master
Rob 2016-05-22 21:36:07 +01:00
parent 8e74d245c7
commit e73e4cd868
2 changed files with 37 additions and 103 deletions

16
lib/DDG/Goodie/Coin.pm Normal file → Executable file
View File

@ -32,13 +32,15 @@ handle query_lc => sub {
return unless @output;
my $result = join(', ', @output);
return (
$result . ' (random)',
structured_answer => {
input => [$flips],
operation => 'Flip coin',
result => $result
});
return $result . ' (random)', structured_answer => {
data => {
title => $result,
subtitle => "Flip coin: $flips"
},
templates => {
group => 'text'
}
};
};
1;

124
t/Coin.t Normal file → Executable file
View File

@ -9,104 +9,36 @@ use DDG::Test::Goodie;
zci answer_type => 'coin';
zci is_cached => 0;
sub build_test {
my ($input, $text, $title) = @_;
return test_zci($text, structured_answer => {
data => {
title => $title,
subtitle => "Flip coin: $input"
},
templates => {
group => 'text'
}
});
}
my $single_text_re = re(qr/(heads|tails) \(random\)/);
my $single_title_re = re(qr/^(heads|tails)$/);
ddg_goodie_test(
[qw( DDG::Goodie::Coin )],
'flip a coin' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'flip coin' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'coin flip' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'coin toss' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'flip 1 coin' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'flip 2 coins' => test_zci(
re(qr/(heads|tails), (heads|tails) \(random\)/),
structured_answer => {
input => [2],
operation => 'Flip coin',
result => re(qr/(heads|tails), /)
}
),
'toss a coin' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'toss 1 coin' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'toss 2 coins' => test_zci(
re(qr/(heads|tails), (heads|tails) \(random\)/),
structured_answer => {
input => [2],
operation => 'Flip coin',
result => re(qr/(heads|tails), /)
}
),
'heads or tails' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'heads or tails?' => test_zci(
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => re(qr/^(heads|tails)$/)
}
),
'flip 4 coins' => test_zci(
re(qr/((heads|tails),? ){4}\(random\)/),
structured_answer => {
input => [4],
operation => 'Flip coin',
result => re(qr/(heads|tails),? /)
}
),
'flip a coin' => build_test(1, $single_text_re, $single_title_re),
'flip coin' => build_test(1, $single_text_re, $single_title_re),
'coin flip' => build_test(1, $single_text_re, $single_title_re),
'coin toss' => build_test(1, $single_text_re, $single_title_re),
'flip 1 coin' => build_test(1, $single_text_re, $single_title_re),
'heads or tails' => build_test(1, $single_text_re, $single_title_re),
'heads or tails?' => build_test(1, $single_text_re, $single_title_re),
'toss a coin' => build_test(1, $single_text_re, $single_title_re),
'toss 1 coin' => build_test(1, $single_text_re, $single_title_re),
'flip 2 coins' => build_test(2, re(qr/(heads|tails), (heads|tails) \(random\)/), re(qr/(heads|tails), /)),
'toss 2 coins' => build_test(2, re(qr/(heads|tails), (heads|tails) \(random\)/), re(qr/(heads|tails), /)),
'flip 4 coins' => build_test(4, re(qr/((heads|tails),? ){4}\(random\)/), re(qr/(heads|tails),? /))
);
done_testing;