module ApproxEq
(
ApproxEq
, approxEqual
, (=~)
, assertApproxEqual
, (@?~)
) where
import Control.Monad ( unless )
import GHC.Stack (HasCallStack)
import qualified Test.HUnit as H
class Show s => ApproxEq s where
approxEqual :: s -> s -> Float -> Bool
(=~) :: s -> s -> Bool
(=~) a b = approxEqual a b 0.0001
assertApproxEqual :: (HasCallStack) => s -> s -> Float -> H.Assertion
assertApproxEqual expected actual epsilon = let eq = approxEqual expected actual epsilon in
unless eq (H.assertFailure msg)
where msg = "expected: " ++ show expected ++ "\n but got: " ++ show actual
(@?~) :: s -> s -> H.Assertion
(@?~) expected actual = assertApproxEqual expected actual 0.01