Tidied up some test functions and added assertNotEqual function

This commit is contained in:
Neil Brown 2007-08-18 14:48:23 +00:00
parent 8ab4299553
commit 68a3b3f4bc
2 changed files with 7 additions and 4 deletions

View File

@ -48,8 +48,11 @@ makeLiteralString str = A.Literal m (A.Array [A.Dimension (length str)] A.Byte)
makeLiteralChar c = A.ArrayElemExpr $ A.Literal m A.Byte (A.ByteLiteral m [c] {-(show (fromEnum c))-}) makeLiteralChar c = A.ArrayElemExpr $ A.Literal m A.Byte (A.ByteLiteral m [c] {-(show (fromEnum c))-})
assertEqualCustom :: (Show a) => String -> (a -> a -> Bool) -> a -> a -> Assertion assertCompareCustom :: (Show a) => String -> (a -> a -> Bool) -> a -> a -> Assertion
assertEqualCustom preface cmp expected actual = assertCompareCustom preface cmp expected actual =
unless (cmp actual expected) (assertFailure msg) unless (cmp actual expected) (assertFailure msg)
where msg = (if null preface then "" else preface ++ "\n") ++ where msg = (if null preface then "" else preface ++ "\n") ++
"expected: " ++ show expected ++ "\n but got: " ++ show actual "expected: " ++ show expected ++ "\n*** got: " ++ show actual
assertNotEqual :: (Show a,Eq a) => String -> a -> a -> Assertion
assertNotEqual msg = assertCompareCustom msg (/=)

View File

@ -14,7 +14,7 @@ import Data.Ord
--(it is an O(N^2) comparison), but thankfully it's only used during testing: --(it is an O(N^2) comparison), but thankfully it's only used during testing:
assertEqualWR :: String -> UC.WrittenRead -> UC.WrittenRead -> Assertion assertEqualWR :: String -> UC.WrittenRead -> UC.WrittenRead -> Assertion
assertEqualWR text exp act assertEqualWR text exp act
= assertEqualCustom text inefficientEqual exp act = assertCompareCustom text inefficientEqual exp act
where where
--We can assume there are no duplicates, because getVars will remove duplicates, and --We can assume there are no duplicates, because getVars will remove duplicates, and
--our expected values in tests should not have duplicate entries --our expected values in tests should not have duplicate entries