X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FAssertions.hs;h=b2ec7c15ef70fee0ad4b9c189ce9249b4c33b7f8;hb=cf2126c163fc1cf26175da1c7200a0ec1e3e034d;hp=8efd12340b04408c6e5916271d01c25977e368a3;hpb=62e6ea5912a0ef9b21d034590700d6b450f942fb;p=spline3.git diff --git a/src/Assertions.hs b/src/Assertions.hs index 8efd123..b2ec7c1 100644 --- a/src/Assertions.hs +++ b/src/Assertions.hs @@ -1,26 +1,35 @@ +-- | The Assertions module contains assertions for use in HUnit +-- tests. They primarily fill the need for an equality test that +-- works with floating point numbers. module Assertions where import Control.Monad (unless) -import Test.HUnit +import Test.HUnit (Assertion, + assertBool, + assertFailure) -import Comparisons -import Point +import Comparisons ((~=)) +import Point (Point, is_close) -- | An HUnit assertion that wraps the almost_equals function. Stolen --- from the definition of assertEqual in Test/HUnit/Base.hs. +-- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs. assertAlmostEqual :: String -> Double -> Double -> Assertion assertAlmostEqual preface expected actual = unless (actual ~= expected) (assertFailure msg) - where msg = (if null preface then "" else preface ++ "\n") ++ - "expected: " ++ show expected ++ "\n but got: " ++ show actual + where msg = (if null preface then "" else preface ++ "\n") ++ + "expected: " ++ show expected ++ "\n but got: " ++ show actual -- | An HUnit assertion that wraps the is_close function. Stolen --- from the definition of assertEqual in Test/HUnit/Base.hs. +-- from the definition of 'assertEqual' in Test\/HUnit\/Base.hs. assertClose :: String -> Point -> Point -> Assertion assertClose preface expected actual = unless (actual `is_close` expected) (assertFailure msg) - where msg = (if null preface then "" else preface ++ "\n") ++ - "expected: " ++ show expected ++ "\n but got: " ++ show actual + where msg = (if null preface then "" else preface ++ "\n") ++ + "expected: " ++ show expected ++ "\n but got: " ++ show actual + +-- | It's asinine that this doesn't exist already. +assertTrue :: String -> Bool -> Assertion +assertTrue = assertBool