]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Assertions.hs
spline3.cabal: update to v1.0.1.
[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.Tasty.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\/Tasty\/HUnit\/Orig.hs.
21 --
22 assertAlmostEqual :: String -- ^ The message prefix
23 -> Double -- ^ The expected value
24 -> Double -- ^ The actual value
25 -> Assertion
26 assertAlmostEqual preface expected actual =
27 unless (actual ~= expected) (assertFailure msg)
28 where msg = (if null preface then "" else preface ++ "\n") ++
29 "expected: " ++ show expected ++ "\n but got: " ++ show actual
30
31
32
33 -- | It's asinine that this doesn't exist already.
34 --
35 assertTrue :: String -> Bool -> Assertion
36 assertTrue = assertBool