Merge remote-tracking branch 'lamanh/fix_2767_CoffeeToWaterRatio' into mintsoft/CoffeeToWaterRatio-template
commit
c88bedcd8b
|
@ -47,18 +47,26 @@ sub convertResult {
|
|||
my ($unit, $weight, $weight_display, $water_ratio, $precision, $fluid_units) = @_;
|
||||
my $conversion = nearest($precision, $weight * $water_ratio);
|
||||
return $conversion . " " . $fluid_units . " of water", structured_answer => {
|
||||
input => [$weight_display . $unit],
|
||||
operation => 'Water calculation for coffee weight',
|
||||
result => "$conversion $fluid_units of water",
|
||||
data => {
|
||||
title => "$conversion $fluid_units of water",
|
||||
subtitle => 'Water calculation for coffee weight: ' . $weight_display . $unit,
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
handle remainder => sub {
|
||||
|
||||
return "1 g to 16.7 ml (0.035 oz. to 0.56 fl. oz.)", structured_answer => {
|
||||
input => [''],
|
||||
operation => 'Coffee to water ratio per gram (0.035 ounces)',
|
||||
result => "16.7 ml (0.56 fl. oz.)",
|
||||
data => {
|
||||
title => '16.7 ml (0.56 fl. oz.)',
|
||||
subtitle => 'Coffee to water ratio per gram (0.035 ounces):',
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
},
|
||||
} unless $_;
|
||||
|
||||
return unless my ($weight_ns) = $_ =~ qr/($weight_re)/;
|
||||
|
|
|
@ -9,75 +9,45 @@ use DDG::Test::Goodie;
|
|||
zci answer_type => "coffee_to_water_ratio";
|
||||
zci is_cached => 1;
|
||||
|
||||
sub build_structured_answer {
|
||||
my ($input, $result) = @_;
|
||||
my ($title, $subtitle);
|
||||
if ($input eq '') {
|
||||
$subtitle = "Coffee to water ratio per gram (0.035 ounces):";
|
||||
$title = "16.7 ml (0.56 fl. oz.)";
|
||||
} else {
|
||||
$subtitle = "Water calculation for coffee weight: $input";
|
||||
$title = $result;
|
||||
}
|
||||
return $result,
|
||||
structured_answer => {
|
||||
data => {
|
||||
title => $title,
|
||||
subtitle => $subtitle,
|
||||
},
|
||||
templates => {
|
||||
group => 'text',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sub build_test { test_zci(build_structured_answer(@_)) }
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::CoffeeToWaterRatio )],
|
||||
|
||||
'30g coffee to water' => test_zci("501 ml of water",
|
||||
structured_answer => {
|
||||
input => ['30g'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "501 ml of water"
|
||||
}
|
||||
),
|
||||
'coffee to water 30G' => test_zci("501 ml of water",
|
||||
structured_answer => {
|
||||
input => ['30G'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "501 ml of water"
|
||||
}
|
||||
),
|
||||
'coffee to water ratio 1 ounce' => test_zci("16 fl. oz. of water",
|
||||
structured_answer => {
|
||||
input => ['1ounce'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "16 fl. oz. of water"
|
||||
}
|
||||
),
|
||||
'31.2 grams coffee to water ratio' => test_zci("521 ml of water",
|
||||
structured_answer => {
|
||||
input => ['31.2grams'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "521 ml of water"
|
||||
}
|
||||
),
|
||||
'coffee to water .5Oz' => test_zci("8 fl. oz. of water",
|
||||
structured_answer => {
|
||||
input => ['.5Oz'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "8 fl. oz. of water"
|
||||
}
|
||||
),
|
||||
'COFFEE TO WATER' => test_zci("1 g to 16.7 ml (0.035 oz. to 0.56 fl. oz.)",
|
||||
structured_answer => {
|
||||
input => [''],
|
||||
operation => "Coffee to water ratio per gram (0.035 ounces)",
|
||||
result => "16.7 ml (0.56 fl. oz.)"
|
||||
}
|
||||
),
|
||||
'coffee to water ratio' => test_zci("1 g to 16.7 ml (0.035 oz. to 0.56 fl. oz.)",
|
||||
structured_answer => {
|
||||
input => [''],
|
||||
operation => "Coffee to water ratio per gram (0.035 ounces)",
|
||||
result => "16.7 ml (0.56 fl. oz.)"
|
||||
}
|
||||
),
|
||||
'coffee to water 20 rgams' => => test_zci("334 ml of water",
|
||||
structured_answer => {
|
||||
input => ['20g'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "334 ml of water"
|
||||
}
|
||||
),
|
||||
'30g coffee to water' => build_test('30g', "501 ml of water"),
|
||||
'coffee to water 30G' => build_test('30G', "501 ml of water"),
|
||||
'coffee to water ratio 1 ounce' => build_test('1ounce', "16 fl. oz. of water"),
|
||||
'31.2 grams coffee to water ratio' => build_test('31.2grams', "521 ml of water"),
|
||||
'coffee to water .5Oz' => build_test('.5Oz', "8 fl. oz. of water"),
|
||||
'COFFEE TO WATER' => build_test('', "1 g to 16.7 ml (0.035 oz. to 0.56 fl. oz.)"),
|
||||
'coffee to water ratio' => build_test('', "1 g to 16.7 ml (0.035 oz. to 0.56 fl. oz.)"),
|
||||
'coffee to water 20 rgams' => build_test('20g', "334 ml of water"),
|
||||
'coffee to water 30 garms' => build_test('30g', "501 ml of water"),
|
||||
'29387293847g coffee to water ratio' => undef,
|
||||
'29387293847 coffee to water ratio' => undef,
|
||||
'coffee to water sdkmfsdkjfh' => undef,
|
||||
'coffee to water 30 garms' => test_zci("501 ml of water",
|
||||
structured_answer => {
|
||||
input => ['30g'],
|
||||
operation => "Water calculation for coffee weight",
|
||||
result => "501 ml of water"
|
||||
}
|
||||
),
|
||||
'29387293847 coffee to water ratio' => undef,
|
||||
'coffee to water sdkmfsdkjfh' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue