1 -- | The Assertions module contains assertions for use in HUnit
2 -- tests. They primarily fill the need for an equality test that
3 -- works with floating point numbers.
7 import Control.Monad (unless)
8 import Test.HUnit (Assertion,
12 import Comparisons ((~=))
15 -- | An HUnit assertion that wraps the almost_equals function. Stolen
16 -- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs.
17 assertAlmostEqual :: String -> Double -> Double -> Assertion
18 assertAlmostEqual preface expected actual =
19 unless (actual ~= expected) (assertFailure msg)
20 where msg = (if null preface then "" else preface ++ "\n") ++
21 "expected: " ++ show expected ++ "\n but got: " ++ show actual
25 -- | It's asinine that this doesn't exist already.
26 assertTrue :: String -> Bool -> Assertion
27 assertTrue = assertBool