Skip to content

Commit

Permalink
trying
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoerzen committed Sep 12, 2007
1 parent d26d06f commit fcee5d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 21 additions & 2 deletions testsrc/TestInfrastructure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ import Data.Word
import Data.List
import Data.Monoid

class (Arbitrary a, Show a, Eq a, Eq b, LL.ListLike a b) => TestLL a b where
llcmp :: a -> [b] -> Bool

llcmp f l = (LL.toList f) == l

instance (Arbitrary a, Show a, Eq a) => TestLL [a] a where
llcmp x y = x == y

instance (Arbitrary a, Show a, Eq a) => TestLL (MyList a) a where
llcmp (MyList x) l = x == l

instance (Show k, Show v, Arbitrary k, Arbitrary v, Ord v, Ord k) => TestLL (Map.Map k v) (k, v) where
llcmp m l = (sort (LL.toList m)) == (sort $ convl $ l)
where convl = foldl myinsert []
myinsert [] newval = [newval]
myinsert ((ak, av):as) (nk, nv)
| ak == nk = (nk, nv) : as
| otherwise = (ak, av) : myinsert as (nk, nv)

data MyList a = MyList [a]

instance (Show a) => Show (MyList a) where
Expand Down Expand Up @@ -104,7 +123,7 @@ t msg test = TestLabel msg $ TestCase $ (run test defOpt >>= checResult)
-- ++ " cases)")

-- | all props, 2 args: full and item
apfi :: String -> (forall f i. (Eq i, Eq f, LL.ListLike f i) => (f -> i -> Bool)) -> Test
apfi :: String -> (forall f i. (Eq i, Eq f, TestLL f i, LL.ListLike f i) => (f -> i -> Bool)) -> Test
apfi msg x = TestLabel msg $ TestList $
[t "[Int]" (x::[Int] -> Int -> Bool),
t "MyList Int" (x::MyList Int -> Int -> Bool),
Expand All @@ -121,7 +140,7 @@ apfi msg x = TestLabel msg $ TestList $
]

-- | all props, 1 arg: full
apf :: String -> (forall f i. (Eq i, Eq f, LL.ListLike f i) => (f -> Bool)) -> Test
apf :: String -> (forall f i. (Eq i, Eq f, TestLL f i, LL.ListLike f i) => (f -> Bool)) -> Test
apf msg func =
apfi msg newfunc
where newfunc x y = func (asTypeOf x (LL.singleton y))
Expand Down
4 changes: 3 additions & 1 deletion testsrc/runtests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ prop_tofromlist f =
where l = LL.toList f

prop_length f = LL.length f == length (LL.toList f)
prop_cons f i = llcmp (LL.cons i f) (i : (LL.toList f))

allt = [apf "empty" prop_empty,
apf "length" prop_length,
apf "to/fromList" prop_tofromlist,
apfi "singleton" prop_singleton]
apfi "singleton" prop_singleton,
apfi "cons" prop_cons]

testh = runTestTT (TestList allt)

Expand Down

0 comments on commit fcee5d8

Please sign in to comment.