googlepolyline 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+134/−3 lines, 3 filesdep +googlepolylinePVP ok
version bump matches the API change (PVP)
Dependencies added: googlepolyline
API changes (from Hackage documentation)
Files
- googlepolyline.cabal +13/−3
- tests/QuickCheck.hs +24/−0
- tests/Units.hs +97/−0
googlepolyline.cabal view
@@ -2,9 +2,10 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: googlepolyline-version: 0.1.0.0+version: 0.1.0.1 synopsis: Google Polyline Encoder/Decoder--- description: +description: + Encoding and decoding functions for Google Maps' polyline format. license: MIT license-file: LICENSE author: Lorne Applebaum@@ -12,9 +13,15 @@ -- copyright: category: Data, Text build-type: Simple+Homepage: https://github.com/lornap/googlepolyline+Bug-reports: https://github.com/lornap/googlepolyline/issues -- extra-source-files: cabal-version: >=1.10 +source-repository head+ type: git+ location: https://github.com/lornap/googlepolyline+ library exposed-modules: Data.Text.GooglePolyline -- other-modules: @@ -27,8 +34,11 @@ Test-Suite test-googlepolyline type: exitcode-stdio-1.0- hs-source-dirs: tests, src+ hs-source-dirs: tests+ other-modules: Units+ , QuickCheck build-depends: base >=4.7 && <4.8+ , googlepolyline , bytestring >= 0.10 && <0.11 , text >= 1.2 && <1.3 , HUnit >= 1.2 && <1.3
+ tests/QuickCheck.hs view
@@ -0,0 +1,24 @@+module QuickCheck where++import Test.QuickCheck+import Data.Text.GooglePolyline+import Control.Applicative ( (<$>) )++cRound :: Double -> Double+cRound = (/1e5) . fromIntegral . round . (*1e5)++pRound :: LatLong -> LatLong+pRound ( LatLong a b ) = LatLong (cRound a) (cRound b )++arbitraryCoord :: Gen LatLong+arbitraryCoord = do+ lat <- choose (-90.0,90.0)+ lon <- choose (-180.0,180.0)+ return $ pRound (LatLong lat lon)++instance Arbitrary LatLong where+ arbitrary = arbitraryCoord++prop_decodeInverse :: [ LatLong ] -> Bool +prop_decodeInverse cs =+ fmap pRound ( decode . encode $ cs ) == fmap pRound cs
+ tests/Units.hs view
@@ -0,0 +1,97 @@+{-# LANGUAGE OverloadedStrings #-}+module Units where++import Test.HUnit++import Data.Text.GooglePolyline++import qualified Data.Text as T++maxDiff :: [ LatLong ] -> [ LatLong ] -> Double+maxDiff p q = maximum $+ zipWith + ( \(LatLong x y) (LatLong a b) -> + sqrt ( ( a - x )^2 + ( b - y )^2 ) ) p q++assertPathEqual :: String -> [ LatLong ] -> [ LatLong ] -> Assertion+assertPathEqual s p1 p2 = assertBool s ( maxDiff p1 p2 < 1e-10 )++datNWenc :: T.Text+datNWenc = "i}q~FrdzuO"++datNWdec :: [ LatLong ]+datNWdec = [LatLong 41.87621 (-87.6297)]++singlePointNWenc :: Assertion+singlePointNWenc =+ assertEqual "Encode Single Point NW" datNWenc ( encode datNWdec )++singlePointNWdec :: Assertion+singlePointNWdec =+ assertEqual "Decode Single Point NW" datNWdec ( decode datNWenc )++datNEenc :: T.Text+datNEenc = "gqp|F}vjuA"++datNEdec :: [ LatLong ]+datNEdec = [LatLong 41.54148 14.15039]++singlePointNEenc :: Assertion+singlePointNEenc =+ assertEqual "Encode Single Point NE" datNEenc ( encode datNEdec )++singlePointNEdec :: Assertion+singlePointNEdec = + assertEqual "Decode Single Point NE" datNEdec ( decode datNEenc )++datSWenc :: T.Text+datSWenc = "x`hmEha|oL"++datSWdec :: [ LatLong ]+datSWdec = [LatLong (-33.79741) (-70.92773)]++singlePointSWenc :: Assertion+singlePointSWenc =+ assertEqual "Encode Single Point SW" datSWenc ( encode datSWdec )++singlePointSWdec :: Assertion+singlePointSWdec =+ assertEqual "Decode Single Point SW" datSWdec ( decode datSWenc )++datSEenc :: T.Text+datSEenc = "`zfuE__~lY"++datSEdec :: [ LatLong ]+datSEdec = [LatLong (-35.10193) 138.60352]++singlePointSEenc :: Assertion+singlePointSEenc =+ assertEqual "Encode Single Point SE" datSEenc ( encode datSEdec )++singlePointSEdec :: Assertion+singlePointSEdec =+ assertEqual "Decode Single Point SE" datSEdec ( decode datSEenc )++singlePointZeroEnc :: Assertion+singlePointZeroEnc =+ assertEqual "Encode zero point (0,0)" "??" ( encode $ [LatLong 0 0] )++singlePointZeroDec :: Assertion+singlePointZeroDec =+ assertEqual "Encode zero point (0,0)" [LatLong 0 0] ( decode "??" )++dat3PathEnc :: T.Text+dat3PathEnc = "iftwFdlsbM~_Ak_AxiAppA"++dat3PathDec :: [ LatLong ]+dat3PathDec = [LatLong 40.74101 (-73.99635)+ ,LatLong 40.73061 (-73.98605)+ ,LatLong 40.71864 (-73.99910)]++threePointPathEnc :: Assertion+threePointPathEnc =+ assertEqual "Encode Three point path" dat3PathEnc ( encode dat3PathDec )++threePointPathDec :: Assertion+threePointPathDec =+ assertPathEqual "Decode Three point path" dat3PathDec ( decode dat3PathEnc )