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