]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Assertions.hs
Move all of the trilinear coefficient tests into the Tests.Grid module.
[spline3.git] / src / Assertions.hs
diff --git a/src/Assertions.hs b/src/Assertions.hs
new file mode 100644 (file)
index 0000000..8efd123
--- /dev/null
@@ -0,0 +1,26 @@
+module Assertions
+where
+
+import Control.Monad (unless)
+import Test.HUnit
+
+import Comparisons
+import Point
+
+-- | An HUnit assertion that wraps the almost_equals function. Stolen
+--   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
+
+
+-- | An HUnit assertion that wraps the is_close function. Stolen
+--   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
+