1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00
semantic/test/OrderedMapSpec.hs
2015-12-14 18:20:21 -05:00

45 lines
1.4 KiB
Haskell

module OrderedMapSpec where
import OrderedMap as Map
import Test.Hspec
spec :: Spec
spec = do
describe "difference" $ do
it "should return those elements of a not in b" $
Map.difference a b `shouldBe` (Map.fromList [ ("a", 1) ])
it "is asymmetrical" $ do
Map.difference a b `shouldNotBe` Map.difference b a
describe "union" $ do
it "should return those elements in either a or b" $
Map.union a b `shouldBe` (Map.fromList $ Map.toList a ++ [ ("d", -4) ])
it "is asymmetrical" $ do
Map.union a b `shouldNotBe` Map.union b a
describe "unions" $ do
it "is equivalent to `union` for two maps" $
Map.unions [ a, b ] `shouldBe` Map.union a b
it "does not duplicate elements" $
Map.unions [ a, b, a, b, a, b ] `shouldBe` Map.union a b
describe "intersectionWith" $ do
it "should return those elements in both a and b, combined with a function" $
Map.intersectionWith (-) a b `shouldBe` (Map.fromList [ ("b", 4), ("c", 6) ])
it "is asymmetrical" $ do
Map.intersectionWith (-) a b `shouldNotBe` Map.intersectionWith (-) b a
describe "keys" $ do
it "should return all the keys in a map" $
Map.keys a `shouldBe` [ "a", "b", "c" ]
it "is ordered" $
Map.keys (Map.union b a) `shouldBe` [ "b", "c", "d", "a" ]
where a = Map.fromList [ ("a", 1), ("b", 2), ("c", 3) ]
b = Map.fromList [ ("b", -2), ("c", -3), ("d", -4) ]