Updates CallingCodes Goodie Re #2767 (#2864)

master
Hugo Thiessard 2016-04-28 20:25:14 +02:00 committed by Ben Moon
parent 2b0d873016
commit 1789d18039
2 changed files with 79 additions and 326 deletions

View File

@ -46,11 +46,15 @@ handle remainder => sub {
my $country_list = list2string(@countries);
return $dialing_code . ' is the international calling code for ' . $country_list . '.',
structured_answer => {
input => [$in_number ? $dialing_code : $country_list],
operation => 'International calling code',
result => ($in_number ? $country_list : $dialing_code),
};
structured_answer => {
data => {
title => $in_number ? $country_list : $dialing_code,
subtitle => 'International calling code: ' . ($in_number ? $dialing_code : $country_list)
},
templates => {
group => 'text'
}
};
};
# Convert a list of country names to a single human readable English string.

View File

@ -9,332 +9,81 @@ use DDG::Test::Goodie;
zci answer_type => "calling_codes";
zci is_cached => 1;
my $txt = "is the international calling code for";
sub build_structured_answer_to_country {
my ($country_list, $dialing_code) = @_;
return $dialing_code . ' is the international calling code for ' . $country_list . '.',
structured_answer => {
data => {
title => $country_list,
subtitle => 'International calling code: ' .$dialing_code
},
templates => {
group => 'text'
}
};
}
sub build_structured_answer_to_code {
my ($country_list, $dialing_code) = @_;
return $dialing_code . ' is the international calling code for ' . $country_list . '.',
structured_answer => {
data => {
title => $dialing_code,
subtitle => 'International calling code: ' . $country_list
},
templates => {
group => 'text'
}
};
}
sub build_test_to_country { test_zci(build_structured_answer_to_country(@_)) }
sub build_test_to_code { test_zci(build_structured_answer_to_code(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::CallingCodes )],
# Example queries
"calling code 55" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"dialing code brazil" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['Brazil'],
operation => 'International calling code',
result => '+55'
}
),
"dialing code +55" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"country calling code 55" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"calling code 55" => build_test_to_country('Brazil', '+55'),
"dialing code brazil" => build_test_to_code('Brazil', '+55'),
"dialing code +55" => build_test_to_country('Brazil', '+55'),
"country calling code 55" => build_test_to_country('Brazil', '+55'),
# Other working queries.
"calling code for the sudan" => test_zci(
"+249 $txt Sudan.",
structured_answer => {
input => ['Sudan'],
operation => 'International calling code',
result => '+249'
}
),
"calling code for vatican" => test_zci(
"+379 $txt the Holy See (Vatican City State).",
structured_answer => {
input => ['the Holy See (Vatican City State)'],
operation => 'International calling code',
result => '+379'
}
),
"379 calling code vatican" => test_zci(
"+379 $txt the Holy See (Vatican City State).",
structured_answer => {
input => ['+379'],
operation => 'International calling code',
result => 'the Holy See (Vatican City State)'
}
),
"vatican calling code 379" => test_zci(
"+379 $txt the Holy See (Vatican City State).",
structured_answer => {
input => ['the Holy See (Vatican City State)'],
operation => 'International calling code',
result => '+379'
}
),
"country dial in code brazil" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['Brazil'],
operation => 'International calling code',
result => '+55'
}
),
"calling code 55 Brazil" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"calling code for Brazil +55" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['Brazil'],
operation => 'International calling code',
result => '+55'
}
),
"calling code +55 for Brazil" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"Brazil calling code +55" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['Brazil'],
operation => 'International calling code',
result => '+55'
}
),
"+55 calling code for Brazil" => test_zci(
"+55 $txt Brazil.",
structured_answer => {
input => ['+55'],
operation => 'International calling code',
result => 'Brazil'
}
),
"calling code 65" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['+65'],
operation => 'International calling code',
result => 'Singapore'
}
),
"calling code +65" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['+65'],
operation => 'International calling code',
result => 'Singapore'
}
),
"dialing code +65" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['+65'],
operation => 'International calling code',
result => 'Singapore'
}
),
"international dial-in code +65" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['+65'],
operation => 'International calling code',
result => 'Singapore'
}
),
"calling code for Singapore" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['Singapore'],
operation => 'International calling code',
result => '+65'
}
),
"country calling code for Singapore" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['Singapore'],
operation => 'International calling code',
result => '+65'
}
),
"dialing code Singapore" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['Singapore'],
operation => 'International calling code',
result => '+65'
}
),
"dialing code for Singapore" => test_zci(
"+65 $txt Singapore.",
structured_answer => {
input => ['Singapore'],
operation => 'International calling code',
result => '+65'
}
),
"dialing code for UK" => test_zci(
"+44 $txt the United Kingdom.",
structured_answer => {
input => ['the United Kingdom'],
operation => 'International calling code',
result => '+44'
}
),
"calling code for the UK" => test_zci(
"+44 $txt the United Kingdom.",
structured_answer => {
input => ['the United Kingdom'],
operation => 'International calling code',
result => '+44'
}
),
"uk calling code" => test_zci(
"+44 $txt the United Kingdom.",
structured_answer => {
input => ['the United Kingdom'],
operation => 'International calling code',
result => '+44'
}
),
"gb calling code" => test_zci(
"+44 $txt the United Kingdom.",
structured_answer => {
input => ['the United Kingdom'],
operation => 'International calling code',
result => '+44'
}
),
"calling code for antigua" => test_zci(
"+1 $txt Antigua and Barbuda.",
structured_answer => {
input => ['Antigua and Barbuda'],
operation => 'International calling code',
result => '+1'
}
),
"calling code for barbuda" => test_zci(
"+1 $txt Antigua and Barbuda.",
structured_answer => {
input => ['Antigua and Barbuda'],
operation => 'International calling code',
result => '+1'
}
),
"calling code for trinidad" => test_zci(
"+1 $txt Trinidad and Tobago.",
structured_answer => {
input => ['Trinidad and Tobago'],
operation => 'International calling code',
result => '+1'
}
),
"calling code for tobago" => test_zci(
"+1 $txt Trinidad and Tobago.",
structured_answer => {
input => ['Trinidad and Tobago'],
operation => 'International calling code',
result => '+1'
}
),
"dialing code for US" => test_zci(
"+1 $txt the United States.",
structured_answer => {
input => ['the United States'],
operation => 'International calling code',
result => '+1'
}
),
"calling code for america" => test_zci(
"+1 $txt the United States.",
structured_answer => {
input => ['the United States'],
operation => 'International calling code',
result => '+1'
}
),
"dial in code +1" => test_zci(
"+1 $txt Antigua and Barbuda, Anguilla, American Samoa, Barbados, Bermuda, the Bahamas, Canada, Dominica, the Dominican Republic, Grenada, Guam, Jamaica, Saint Lucia, Saint Kitts and Nevis, the Cayman Islands, the Northern Mariana Islands, Montserrat, Puerto Rico, Turks and Caicos Islands, Trinidad and Tobago, the United States, Saint Vincent and the Grenadines, the British Virgin Islands, and the US Virgin Islands.",
structured_answer => {
input => ['+1'],
operation => 'International calling code',
result => qr/^Antigua.* US Virgin Islands$/,
}
),
"calling code +7" => test_zci(
"+7 $txt the Russian Federation and Kazakhstan.",
structured_answer => {
input => ['+7'],
operation => 'International calling code',
result => 'the Russian Federation and Kazakhstan'
}
),
"calling code for russia" => test_zci(
"+7 $txt the Russian Federation.",
structured_answer => {
input => ['the Russian Federation'],
operation => 'International calling code',
result => '+7'
}
),
"dial in code to the Russian Federation" => test_zci(
"+7 $txt the Russian Federation.",
structured_answer => {
input => ['the Russian Federation'],
operation => 'International calling code',
result => '+7'
}
),
"calling code for south korea" => test_zci(
"+82 $txt the Republic of Korea.",
structured_answer => {
input => ['the Republic of Korea'],
operation => 'International calling code',
result => '+82'
}
),
"calling code for the republic of korea" => test_zci(
"+82 $txt the Republic of Korea.",
structured_answer => {
input => ['the Republic of Korea'],
operation => 'International calling code',
result => '+82'
}
),
"calling code for north korea" => test_zci(
"+850 $txt the Democratic People's Republic of Korea.",
structured_answer => {
input => ['the Democratic People\'s Republic of Korea'],
operation => 'International calling code',
result => '+850'
}
),
"calling code for the democratic people's republic of korea" => test_zci(
"+850 $txt the Democratic People's Republic of Korea.",
structured_answer => {
input => ['the Democratic People\'s Republic of Korea'],
operation => 'International calling code',
result => '+850'
}
),
"calling code for the sudan" => build_test_to_code('Sudan', '+249'),
"calling code for vatican" => build_test_to_code('the Holy See (Vatican City State)', '+379'),
"379 calling code vatican" => build_test_to_country('the Holy See (Vatican City State)', '+379'),
"vatican calling code 379" => build_test_to_code('the Holy See (Vatican City State)', '+379'),
"country dial in code brazil" => build_test_to_code('Brazil', '+55'),
"calling code 55 Brazil" => build_test_to_country('Brazil', '+55'),
"calling code for Brazil +55" => build_test_to_code('Brazil', '+55'),
"calling code +55 for Brazil" => build_test_to_country('Brazil', '+55'),
"Brazil calling code +55" => build_test_to_code('Brazil', '+55'),
"+55 calling code for Brazil" => build_test_to_country('Brazil', '+55'),
"calling code 65" => build_test_to_country('Singapore', '+65'),
"calling code +65" => build_test_to_country('Singapore', '+65'),
"dialing code +65" => build_test_to_country('Singapore', '+65'),
"international dial-in code +65" => build_test_to_country('Singapore', '+65'),
"calling code for Singapore" => build_test_to_code('Singapore', '+65'),
"country calling code for Singapore" => build_test_to_code('Singapore', '+65'),
"dialing code Singapore" => build_test_to_code('Singapore', '+65'),
"dialing code for Singapore" => build_test_to_code('Singapore', '+65'),
"dialing code for UK" => build_test_to_code('the United Kingdom', '+44'),
"calling code for the UK" => build_test_to_code('the United Kingdom', '+44'),
"uk calling code" => build_test_to_code('the United Kingdom', '+44'),
"gb calling code" => build_test_to_code('the United Kingdom', '+44'),
"calling code for antigua" => build_test_to_code('Antigua and Barbuda', '+1'),
"calling code for barbuda" => build_test_to_code('Antigua and Barbuda', '+1'),
"calling code for trinidad" => build_test_to_code('Trinidad and Tobago', '+1'),
"calling code for tobago" => build_test_to_code('Trinidad and Tobago', '+1'),
"dialing code for US" => build_test_to_code('the United States', '+1'),
"calling code for america" => build_test_to_code('the United States', '+1'),
"dial in code +1" => build_test_to_country('Antigua and Barbuda, Anguilla, American Samoa, Barbados, Bermuda, the Bahamas, Canada, Dominica, the Dominican Republic, Grenada, Guam, Jamaica, Saint Lucia, Saint Kitts and Nevis, the Cayman Islands, the Northern Mariana Islands, Montserrat, Puerto Rico, Turks and Caicos Islands, Trinidad and Tobago, the United States, Saint Vincent and the Grenadines, the British Virgin Islands, and the US Virgin Islands', '+1'),
"calling code +7" => build_test_to_country('the Russian Federation and Kazakhstan', '+7'),
"calling code for russia" => build_test_to_code('the Russian Federation', '+7'),
"dial in code to the Russian Federation" => build_test_to_code('the Russian Federation', '+7'),
"calling code for south korea" => build_test_to_code('the Republic of Korea', '+82'),
"calling code for the republic of korea" => build_test_to_code('the Republic of Korea', '+82'),
"calling code for north korea" => build_test_to_code('the Democratic People\'s Republic of Korea', '+850'),
"calling code for the democratic people's republic of korea" => build_test_to_code('the Democratic People\'s Republic of Korea', '+850'),
# Properly negative
'country code for the netherlands' => undef,
'country code for north korea' => undef,