on 92b6021 help sign in
50 lines 1.8 kB history raw
1module Test.TypeRep.CacheMap where
3import Prelude hiding (lookup)
5import Data.Functor.Identity (Identity (..))
6import GHC.Exts (fromList)
7import Test.Tasty.Hspec (Spec, describe, it, shouldBe)
9import Data.TMap (TMap, empty, insert, lookup, one, size, union)
10import Data.TypeRepMap.Internal (WrapTypeable (..))
12-- Simple test for 'lookup', 'insert' and 'size' functions.
13spec_insertLookup :: Spec
14spec_insertLookup = do
15 describe "Lookup Test" $ do
16 it "returns the inserted element" $
17 lookup (fromList [WrapTypeable $ Identity 'a']) `shouldBe` Just 'a'
18 it "returns the second inserted value of the same type" $
19 lookup (fromList [WrapTypeable (Identity 'b'), WrapTypeable (Identity 'a')]) `shouldBe` Just 'b'
21 describe "Size Test" $ do
22 it "is empty" $
23 size empty `shouldBe` 0
24 it "is of size 1 when 1 element inserted" $
25 size (one 'a') `shouldBe` 1
26 it "doesn't increase size when element of the same type is added" $
27 size (insert 'b' $ insert 'a' empty) `shouldBe` 1
28 it "returns 10 when 10 different types are inserted" $
29 size mapOf10 `shouldBe` 10
31 describe "Union test" $ do
32 let m = fromList [WrapTypeable $ Identity 'a', WrapTypeable $ Identity True] `union`
33 fromList [WrapTypeable $ Identity 'b']
34 it "lookup works on union as expected" $ do
35 lookup m `shouldBe` Just 'a'
36 lookup m `shouldBe` Just True
37 lookup @Int m `shouldBe` Nothing
40mapOf10 :: TMap
41mapOf10 = insert True
42 $ insert [True, False]
43 $ insert (Just True)
44 $ insert (Just ())
45 $ insert [()]
46 $ insert ()
47 $ insert "aaa"
48 $ insert (Just 'a')
49 $ insert 'a'
50 $ insert (11 :: Int) empty