]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Assertions.hs
8efd12340b04408c6e5916271d01c25977e368a3
[spline3.git] / src / Assertions.hs
1 module Assertions
2 where
3
4 import Control.Monad (unless)
5 import Test.HUnit
6
7 import Comparisons
8 import Point
9
10 -- | An HUnit assertion that wraps the almost_equals function. Stolen
11 -- from the definition of assertEqual in Test/HUnit/Base.hs.
12 assertAlmostEqual :: String -> Double -> Double -> Assertion
13 assertAlmostEqual preface expected actual =
14 unless (actual ~= expected) (assertFailure msg)
15 where msg = (if null preface then "" else preface ++ "\n") ++
16 "expected: " ++ show expected ++ "\n but got: " ++ show actual
17
18
19 -- | An HUnit assertion that wraps the is_close function. Stolen
20 -- from the definition of assertEqual in Test/HUnit/Base.hs.
21 assertClose :: String -> Point -> Point -> Assertion
22 assertClose preface expected actual =
23 unless (actual `is_close` expected) (assertFailure msg)
24 where msg = (if null preface then "" else preface ++ "\n") ++
25 "expected: " ++ show expected ++ "\n but got: " ++ show actual
26