on wai-extra/3.0.6.1 help sign in
typeable/wai/warp/test/MultiMapSpec.hs
30 lines 1.1 kB history raw
1module MultiMapSpec where
3import Network.Wai.Handler.Warp.MultiMap
4import Test.Hspec
5import Test.QuickCheck (property)
7type Alist = [(Int,Char)]
9spec :: Spec
10spec = do
11 describe "fromList" $ do
12 it "generates a valid tree" $ property $ \xs ->
13 valid $ fromList (xs :: Alist)
14 describe "toSortedList" $ do
15 it "generated a sorted list" $ property $ \xs ->
16 ordered $ toSortedList $ fromList (xs :: Alist)
17 describe "search" $ do
18 it "acts as the list model" $ property $ \x xs ->
19 search x (fromList xs) == lookup x (xs :: Alist)
20 describe "fromSortedList" $ do
21 it "generates a valid tree" $ property $ \xs ->
22 valid . fromSortedList . toSortedList . fromList $ (xs :: Alist)
23 it "maintains the tree with toSortedList" $ property $ \xs ->
24 let t1 = fromList (xs :: Alist)
25 t2 = fromSortedList $ toSortedList t1
26 in t1 == t2
28ordered :: Ord a => [(a, b)] -> Bool
29ordered (x:y:xys) = fst x <= fst y && ordered (y:xys)
30ordered _ = True