mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
some additions to test helpers
This commit is contained in:
@@ -44,6 +44,11 @@ hasElements expected actual = counterexample' (" Expected elements (in any orde
|
||||
++ "\n Was: " ++ show actual)
|
||||
(sort expected == sort actual)
|
||||
|
||||
hasElementsDuplicates expected actual =
|
||||
counterexample' (" Expected elements (in any order, duplicates allowed): " ++ show expected
|
||||
++ "\n Was: " ++ show actual)
|
||||
(nub (sort expected) == nub (sort actual))
|
||||
|
||||
was f actual = counterexample' (" Was: "++show actual) (f actual)
|
||||
|
||||
-- helpers
|
||||
|
||||
+11
-2
@@ -1,7 +1,7 @@
|
||||
{-# LANGUAGE TemplateHaskell, DeriveLift, StandaloneDeriving #-}
|
||||
|
||||
module Mooc.Th (testing, testing', timeLimit,
|
||||
isDefined, withDefined, hasType, importsOnly, show',
|
||||
isDefined, withDefined, hasType, hasType', importsOnly, show',
|
||||
reifyType, DataType(..), FieldType(..), Constructor(..),
|
||||
withInstance, withInstance1, classContains, defineInstance)
|
||||
where
|
||||
@@ -60,6 +60,15 @@ hasType s qtyp = do
|
||||
then [|\k -> counterexample s (k $(varOrCon $ mkName s))|]
|
||||
else [|\k -> counterexample ("The type of '"++s++"'\n Expected: "++expected++"\n Was: "++actual) False|]
|
||||
|
||||
hasType' :: String -> String -> Q Exp
|
||||
hasType' s expected = do
|
||||
mt <- getType s
|
||||
let actual = case mt of Nothing -> "nothing"
|
||||
Just t -> showType t
|
||||
if (actual==expected)
|
||||
then [|\k -> counterexample s (k $(varOrCon $ mkName s))|]
|
||||
else [|\k -> counterexample ("The type of '"++s++"'\n Expected: "++expected++"\n Was: "++actual) False|]
|
||||
|
||||
-- testing types
|
||||
|
||||
data FieldType = SimpleType String | WeirdType
|
||||
@@ -132,7 +141,7 @@ classContains cln varn = do
|
||||
Just cl -> do
|
||||
info <- reify cl
|
||||
case info of
|
||||
(ClassOpI _ _ parent) -> let pn = nameBase parent in [|counterexample ("Function "++varn++ "is in the wrong class!") (pn ?== cln)|]
|
||||
(ClassOpI _ _ parent) -> let pn = nameBase parent in [|counterexample ("Function "++varn++" is in the wrong class!") (pn ?== cln)|]
|
||||
_ -> [|counterexample ("Function "++varn++" is not a method of class "++cln) (property False)|]
|
||||
|
||||
lookupConstructor :: String -> Q (Maybe Type)
|
||||
|
||||
Reference in New Issue
Block a user