]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Assertions.hs
4e09b82974f301762dcdefcd0253e50ceeec3459
[spline3.git] / src / Assertions.hs
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.
4 module Assertions
5 where
6
7 import Control.Monad (unless)
8 import Test.HUnit (Assertion,
9 assertBool,
10 assertFailure)
11
12 import Comparisons ((~=))
13
14
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
22
23
24
25 -- | It's asinine that this doesn't exist already.
26 assertTrue :: String -> Bool -> Assertion
27 assertTrue = assertBool