File: MultiMapSpec.hs

package info (click to toggle)
haskell-warp 3.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 300 kB
  • ctags: 2
  • sloc: haskell: 2,890; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module MultiMapSpec where

import Network.Wai.Handler.Warp.MultiMap
import Test.Hspec
import Test.QuickCheck (property)

type Alist = [(Int,Char)]

spec :: Spec
spec = do
    describe "fromList" $ do
        it "generates a valid tree" $ property $ \xs ->
            valid $ fromList (xs :: Alist)
    describe "toSortedList" $ do
        it "generated a sorted list" $ property $ \xs ->
            ordered $ toSortedList $ fromList (xs :: Alist)
    describe "search" $ do
        it "acts as the list model" $ property $ \x xs ->
            search x (fromList xs) == lookup x (xs :: Alist)
    describe "fromSortedList" $ do
        it "generates a valid tree" $ property $ \xs ->
            valid . fromSortedList . toSortedList . fromList $ (xs :: Alist)
        it "maintains the tree with toSortedList" $ property $ \xs ->
            let t1 = fromList (xs :: Alist)
                t2 = fromSortedList $ toSortedList t1
            in t1 == t2

ordered :: Ord a => [(a, b)] -> Bool
ordered (x:y:xys) = fst x <= fst y && ordered (y:xys)
ordered _         = True