TwelveOclock: add structured_answer.

master
Matt Miller 2014-10-10 11:18:28 +02:00
parent d1a72cefd9
commit a7b8092a19
3 changed files with 50 additions and 23 deletions

View File

@ -50,14 +50,13 @@ handle query => sub {
}
my $answer = $guess_result . '12:00' . $meridian . ' is ' . $to_show . '.';
return $answer, html => format_html($answer);
return $answer,
structured_answer => {
input => [],
operation => 'midnight or noon',
result => $answer
};
};
sub format_html {
my ($answer) = @_;
return "<div class='zci--twelveoclock text--primary'>" . $answer . "</div>";
}
1;

View File

@ -1,6 +0,0 @@
.zci--answer .zci--twelveoclock {
font-size: 1.5em;
font-weight: 300;
padding-top: .25em;
padding-bottom: .25em;
}

View File

@ -8,17 +8,51 @@ use DDG::Test::Goodie;
zci answer_type => "twelve_oclock";
zci is_cached => 1;
my @noon = ('12:00pm is noon.', html => qr/12:00pm is noon./);
my @correct_noon = ('Yes, 12:00pm is noon.', html => qr/Yes, 12:00pm is noon./);
my @wrong_noon = ('No, 12:00pm is noon.', html => qr/No, 12:00pm is noon./);
my @midnight = ('12:00am is midnight.', html => qr/12:00am is midnight./);
my @correct_midnight = ('Yes, 12:00am is midnight.', html => qr/Yes, 12:00am is midnight./);
my @wrong_midnight = ('No, 12:00am is midnight.', html => qr/No, 12:00am is midnight./);
my @noon = (
'12:00pm is noon.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => '12:00pm is noon.'
});
my @correct_noon = (
'Yes, 12:00pm is noon.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => 'Yes, 12:00pm is noon.'
});
my @wrong_noon = (
'No, 12:00pm is noon.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => 'No, 12:00pm is noon.'
});
my @midnight = (
'12:00am is midnight.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => '12:00am is midnight.'
});
my @correct_midnight = (
'Yes, 12:00am is midnight.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => 'Yes, 12:00am is midnight.'
});
my @wrong_midnight = (
'No, 12:00am is midnight.',
structured_answer => {
input => [],
operation => 'midnight or noon',
result => 'No, 12:00am is midnight.'
});
ddg_goodie_test([qw(
DDG::Goodie::TwelveOclock
)
],
ddg_goodie_test(
[qw( DDG::Goodie::TwelveOclock )],
'is 1200a.m. noon' => test_zci(@wrong_midnight),
'is 1200pm noon?' => test_zci(@correct_noon),
'is 12:00 am midnight' => test_zci(@correct_midnight),