+
+ ##
+ # Test identification of UK postcodes using examples from
+ # http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
+ def test_identify_uk_postcode
+ [
+ 'EC1A 1BB',
+ 'W1A 1HQ',
+ 'M1 1AA',
+ 'B33 8TH',
+ 'CR2 6XH',
+ 'DN55 1PT'
+ ].each do |code|
+ post :search, query: code
+ assert_response :success
+ assert_equal ['uk_postcode', 'osm_nominatim'], assigns(:sources)
+ end
+ end
+
+ ##
+ # Test identification of Canadian postcodes
+ def test_identify_ca_postcode
+ post :search, query: 'A1B 2C3'
+ assert_response :success
+ assert_equal ['ca_postcode', 'osm_nominatim'], assigns(:sources)
+ end
+
+ ##
+ # Test identification fall through to the default case
+ def test_identify_default
+ post :search, query: 'foo bar baz'
+ assert_response :success
+ assert_equal ['osm_nominatim'], assigns(:sources)
+ end
+
+private
+
+ ##
+ # this is a test helper for rounding latlon strings to a specified precision, e.g., at a precision
+ # of 5, "50.06773333333334, -14.377416666666667" will become "50.06773, -14.37742"
+ def assert_latlon_equal_round(expected, actual, precision)
+ assert_equal expected.split(',').map {|i| i.to_f.round(precision)}.join(', '), actual.split(',').map {|i| i.to_f.round(precision)}.join(', ')
+ end