2012-09-29 16:25:23 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
2016-05-16 06:07:57 -07:00
|
|
|
use Test::Deep;
|
2012-09-29 16:25:23 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => 'tip';
|
2014-09-27 06:42:57 -07:00
|
|
|
zci is_cached => 1;
|
2012-09-29 16:25:23 -07:00
|
|
|
|
2016-06-11 08:13:37 -07:00
|
|
|
sub make_structured_answer {
|
2017-06-23 14:12:52 -07:00
|
|
|
my ($percentage, $bill_amount) = @_;
|
2016-06-08 18:58:45 -07:00
|
|
|
|
2017-06-23 14:12:52 -07:00
|
|
|
return '', structured_answer => {
|
|
|
|
data => {
|
|
|
|
title => "Tip Calculator",
|
|
|
|
percentage => "$percentage",
|
|
|
|
bill => "$bill_amount",
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text',
|
|
|
|
options => {
|
|
|
|
content => 'DDH.tips.content'
|
2016-06-08 18:58:45 -07:00
|
|
|
},
|
2017-06-23 14:12:52 -07:00
|
|
|
}
|
|
|
|
};
|
2016-06-08 18:58:45 -07:00
|
|
|
}
|
|
|
|
|
2016-06-11 08:13:37 -07:00
|
|
|
sub build_test {test_zci(make_structured_answer(@_))}
|
|
|
|
|
2012-09-29 16:25:23 -07:00
|
|
|
ddg_goodie_test(
|
2014-10-16 04:44:55 -07:00
|
|
|
[qw( DDG::Goodie::Tips)],
|
2017-06-23 14:12:52 -07:00
|
|
|
'20% tip on $20' => build_test('20', '20'),
|
|
|
|
'20% tip on $20 bill' => build_test('20', '20'),
|
|
|
|
'20% tip for a $20 bill' => build_test('20', '20'),
|
|
|
|
'20 percent tip on $20' => build_test('20', '20'),
|
|
|
|
'20% tip on $21.63' => build_test('20', '21.63'),
|
|
|
|
'20 percent tip for a $20 bill' => build_test('20', '20'),
|
|
|
|
'20 percent tip for a $2000 bill' => build_test('20', '2000'),
|
|
|
|
'tip calculator' => build_test('', ''), # undef stringified
|
|
|
|
'calculate tip' => build_test('', ''), # undef stringified
|
|
|
|
# queries that will be handled by the calc
|
|
|
|
'25 percent of 20000' => undef,
|
|
|
|
'2% of 25,000' => undef,
|
|
|
|
'2% of $25,000' => undef,
|
|
|
|
'2,000% of -2' => undef,
|
|
|
|
'20% tax on $20' => undef,
|
|
|
|
# random. definately shouldn't trigger this IA
|
2014-10-16 04:44:55 -07:00
|
|
|
'best of 5' => undef,
|
|
|
|
'4 of 5 dentists' => undef,
|
2017-06-23 14:12:52 -07:00
|
|
|
'yo, give me some tips' => undef,
|
|
|
|
'tips to save cash' => undef,
|
|
|
|
'show me the tip calculator, bro' => undef,
|
2012-09-29 16:25:23 -07:00
|
|
|
);
|
|
|
|
|
2016-05-16 06:18:04 -07:00
|
|
|
done_testing;
|