From 2143643a26aaf2e09e0ec197a1dc8163bc01b80e Mon Sep 17 00:00:00 2001 From: Ben Clifford Date: Wed, 12 Oct 2016 08:26:59 +0000 Subject: [PATCH 1/2] add a simple test. --- reverse-geocoding.cabal | 8 ++++++++ tests/NetworkTest.hs | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/NetworkTest.hs diff --git a/reverse-geocoding.cabal b/reverse-geocoding.cabal index b716c87..2ea8488 100644 --- a/reverse-geocoding.cabal +++ b/reverse-geocoding.cabal @@ -28,6 +28,14 @@ library hs-source-dirs: src default-language: Haskell2010 +test-suite network-test + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: tests + main-is: NetworkTest.hs + build-depends: base, + reverse-geocoding + source-repository head type: git location: https://github.com/jcristovao/reverse-geocoding diff --git a/tests/NetworkTest.hs b/tests/NetworkTest.hs new file mode 100644 index 0000000..c79679b --- /dev/null +++ b/tests/NetworkTest.hs @@ -0,0 +1,9 @@ +import Data.Geolocation.Reverse +import Data.Geolocation.Reverse.Types + +main = do + putStrLn "Network test stub" + -- all we're going to do is get a location and + -- check we don't crash. + l <- getLocationInfoDef (Latitude (Just 5)) (Longitude (Just 5)) + print l From e17885d446b62b2efe366d47d00068a3d21b3223 Mon Sep 17 00:00:00 2001 From: Ben Clifford Date: Wed, 12 Oct 2016 08:54:11 +0000 Subject: [PATCH 2/2] Bugfix very small latitudes/longitudes. These were being rendered with exponential notations which the openstreetmap API was erroring on. This commit switches to using fixed point representation. --- src/Data/Geolocation/Reverse/Providers.hs | 7 +++++-- tests/NetworkTest.hs | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Data/Geolocation/Reverse/Providers.hs b/src/Data/Geolocation/Reverse/Providers.hs index d00890d..9390fb8 100644 --- a/src/Data/Geolocation/Reverse/Providers.hs +++ b/src/Data/Geolocation/Reverse/Providers.hs @@ -22,6 +22,7 @@ import Data.Aeson import Data.Aeson.Types import Control.Monad (join) import qualified Data.Text as T +import Text.Printf import Data.Geolocation.Reverse.Types @@ -41,8 +42,8 @@ openStreetMapUrl (Latitude mlat) (Longitude mlon) = do return $ "http://nominatim.openstreetmap.org/reverse" <> "?format=json" <> "&zoom=18" - <> "&lat=" <> show lat - <> "&lon=" <> show lon + <> "&lat=" <> formatFixed lat + <> "&lon=" <> formatFixed lon getPostCodeText :: Suburb -> Maybe Suburb @@ -77,3 +78,5 @@ openStreetMapParser o = <|?> (o .:? "street") ) <*> o .:? "postcode" + +formatFixed n = printf "%.6f" n diff --git a/tests/NetworkTest.hs b/tests/NetworkTest.hs index c79679b..0de09c6 100644 --- a/tests/NetworkTest.hs +++ b/tests/NetworkTest.hs @@ -2,8 +2,14 @@ import Data.Geolocation.Reverse import Data.Geolocation.Reverse.Types main = do - putStrLn "Network test stub" + -- all we're going to do is get a location and -- check we don't crash. l <- getLocationInfoDef (Latitude (Just 5)) (Longitude (Just 5)) print l + + -- regression test for extremely small numbers that + -- were being rendered using invalid exponential + -- notation. + l2 <- getLocationInfoDef (Latitude (Just 0.0005)) (Longitude (Just 0.0005)) + print l2