Skip to content

Commit

Permalink
Merge pull request #9 from dustin/checkers
Browse files Browse the repository at this point in the history
Use checkers to validate monoid laws
  • Loading branch information
PaulJohnson authored Apr 13, 2018
2 parents e7853db + 863f0ef commit eb186f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion geodetics.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ test-suite GeodeticTest
test-framework >= 0.4.1,
test-framework-quickcheck2,
test-framework-hunit,
array >= 0.4
array >= 0.4,
checkers
hs-source-dirs:
src,
test
Expand Down
21 changes: 20 additions & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Main where

Expand All @@ -12,6 +13,8 @@ import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2 (testProperty)
import qualified Test.HUnit as HU
import Test.QuickCheck
import Test.QuickCheck.Checkers (EqProp, eq, (=-=), unbatch)
import Test.QuickCheck.Classes (monoid)

import ArbitraryInstances
import Geodetics.Altitude
Expand All @@ -38,6 +41,20 @@ main = do

defaultMainWithOpts tests my_runner_opts

instance EqProp GridOffset where
(GridOffset a b c) =-= (GridOffset a' b' c') =
eq True $ a a' && b b' && c c'
where x y = abs (x - y) < 0.00001 *~ meter

instance EqProp Helmert where
(Helmert cX' cY' cZ' s rX' rY' rZ') =-= (Helmert cX'' cY'' cZ'' s' rX'' rY'' rZ'') =
eq True $ and [cX' cX'', cY' cY'', cZ' cZ'',
s ≈- s',
rX' ≈- rX'', rY' ≈- rY'', rZ' ≈- rZ'']

where x y = abs (x - y) < 0.00001 *~ meter
x ≈- y = abs (x - y) < (_1 / (_5 * _2) ** (_5))

tests :: [Test]
tests = [
testGroup "Geodetic" [
Expand Down Expand Up @@ -69,7 +86,9 @@ tests = [
testProperty "Ray Bisection" prop_rayBisect,
testProperty "Rhumb Continuity" prop_rhumbContinuity,
testProperty "Rhumb Intersection" prop_rhumbIntersect
]
],
testGroup "GridOffset" $ map (uncurry testProperty) $ unbatch $ monoid (mempty :: GridOffset),
testGroup "Helmert" $ map (uncurry testProperty) $ unbatch $ monoid (mempty :: Helmert)
]


Expand Down

0 comments on commit eb186f7

Please sign in to comment.