]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Assertions.hs
Import cleanup in Assertions.
[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 --
5 module Assertions (
6 assertAlmostEqual,
7 assertTrue )
8 where
9
10 import Control.Monad ( unless )
11 import Test.HUnit (
12 Assertion,
13 assertBool,
14 assertFailure )
15
16 import Comparisons ( (~=) )
17
18
19 -- | An HUnit assertion that wraps the almost_equals function. Stolen
20 -- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs.
21 assertAlmostEqual :: String -> Double -> Double -> Assertion
22 assertAlmostEqual preface expected actual =
23 unless (actual ~= expected) (assertFailure msg)
24 where msg = (if null preface then "" else preface ++ "\n") ++
25 "expected: " ++ show expected ++ "\n but got: " ++ show actual
26
27
28
29 -- | It's asinine that this doesn't exist already.
30 assertTrue :: String -> Bool -> Assertion
31 assertTrue = assertBool