2014-06-30 20:38:48 -07:00
#!/usr/bin/env perl
use strict ;
use warnings ;
use Test::More ;
2016-05-16 06:07:57 -07:00
use Test::Deep ;
2014-06-30 20:38:48 -07:00
use DDG::Test::Goodie ;
use utf8 ;
zci answer_type = > 'convertlatlon' ;
zci is_cached = > 1 ;
2016-05-15 09:31:26 -07:00
sub build_test
{
my ( $ text , $ input , $ operation , $ answer ) = @ _ ;
return test_zci ( $ text , structured_answer = > {
data = > {
title = > "$answer" ,
subtitle = > "$operation: $input" ,
} ,
templates = > {
group = > 'text'
}
} ) ;
}
2014-06-30 20:38:48 -07:00
2016-05-15 09:31:26 -07:00
ddg_goodie_test (
[ qw( DDG::Goodie::ConvertLatLon ) ] ,
2014-07-04 20:51:17 -07:00
#Primary example
2016-05-15 09:31:26 -07:00
q`71° 10' 3" in decimal` = > build_test ( '71.1675°' , "71° 10′ 3″" , "Convert to decimal" , "71.1675°" ) ,
2014-06-30 20:38:48 -07:00
2014-07-04 20:51:17 -07:00
#Secondary examples
2016-05-15 09:31:26 -07:00
'71 degrees 10 minutes 3 seconds east in decimal' = > build_test ( '71.1675° E' , "71° 10′ 3″ E" , "Convert to decimal" , "71.1675° E" ) ,
q`-16º 30' 0" -68º 9' 0" as decimal` = > build_test ( '-16.5° -68.15°' , "-16° 30′ , -68° 9′ " , "Convert to decimal" , "-16.5°, -68.15°" ) ,
2014-07-04 20:51:17 -07:00
#Latitudes and longitudes of cities, various trigger combinations
#Values from Wikipedia/GeoHack toolserver
#Sydney
2016-05-15 09:31:26 -07:00
'convert 33.859972º S 151.2094° E to degrees minutes seconds' = > build_test ( '33° 51′ 36″ S 151° 12′ 34″ E' , "33.859972° S, 151.2094° E" , "Convert to DMS" , "33° 51′ 36″ S, 151° 12′ 34″ E" ) ,
2014-07-04 20:51:17 -07:00
#Moscow
2016-05-15 09:31:26 -07:00
'55° 45′ 0″ 37° 37′ 0″ in decimal' = > build_test ( '55.75° 37.616667°' , "55° 45′ , 37° 37′ " , "Convert to decimal" , "55.75°, 37.616667°" ) ,
2014-07-04 20:51:17 -07:00
#Kinshasha
2016-05-15 09:31:26 -07:00
'kinshasha is 4.325 degrees south 15.322222 degrees east convert to dms' = > build_test ( '4° 19′ 30″ S 15° 19′ 20″ E' , "4.325° S, 15.322222° E" , "Convert to DMS" , "4° 19′ 30″ S, 15° 19′ 20″ E" ) ,
2014-07-04 20:51:17 -07:00
#Copenhagen
2016-05-15 09:31:26 -07:00
'55.676111° latitude' = > build_test ( '55° 40′ 34″' , "55.676111°" , "Convert to DMS" , "55° 40′ 34″" ) ,
2014-06-30 20:38:48 -07:00
2014-07-04 20:51:17 -07:00
#Make sure "plural S" works
2016-05-15 09:31:26 -07:00
"68 degrees 9 minutes S in decimal form" = > build_test ( '68.15° S' , "68° 9′ S" , "Convert to decimal" , "68.15° S" ) ,
2014-06-30 20:38:48 -07:00
2014-07-04 20:51:17 -07:00
#Should not trigger for impossible latitudes and longitudes
2016-05-15 09:31:26 -07:00
q`95º 4' N as decimal` = > undef ,
2014-07-04 20:51:17 -07:00
'convert 293.11 degrees to dms' = > undef ,
2014-10-28 11:36:15 -07:00
2014-07-04 20:51:17 -07:00
#Should not trigger for impossible combinations of sign and
# cardinal direction
2016-05-15 09:31:26 -07:00
q`-71º 12' 51" S as a decimal latitude` = > undef ,
2014-06-30 20:38:48 -07:00
2014-07-04 20:51:17 -07:00
#Should not trigger on unrelated queries
'convert 61.01º farenheit to celcius' = > undef ,
'how many degrees in a 12-sided polygon internal angles' = > undef ,
'convert 61.125 degrees to radians' = > undef ,
'are there more than 100 seconds in a day' = > undef ,
'convert 4 minute mile to kilometers' = > undef ,
2016-05-15 09:31:26 -07:00
q`attack of the 50' 4" woman` = > undef ,
2014-07-04 20:51:17 -07:00
'is 39.75 degrees a fever' = > undef ,
2014-07-05 05:19:53 -07:00
'convert 39.75 degrees to farenheit' = > undef ,
2014-06-30 20:38:48 -07:00
2014-07-04 22:00:59 -07:00
#Check for to-format name
2016-05-15 09:31:26 -07:00
'16.5° S, 68.15° W dms' = > build_test ( "16° 30′ S 68° 9′ W" , "16.5° S, 68.15° W" , "Convert to DMS" , "16° 30′ S, 68° 9′ W" ) ,
'16° 30′ S, 68° 9′ W decimal' = > build_test ( "16.5° S 68.15° W" , "16° 30′ S, 68° 9′ W" , "Convert to decimal" , "16.5° S, 68.15° W" ) ,
2014-06-30 20:38:48 -07:00
) ;
done_testing ;