1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00
semantic/test/OrderedMapSpec.hs

46 lines
1.4 KiB
Haskell
Raw Normal View History

2015-12-15 01:42:57 +03:00
module OrderedMapSpec where
2016-05-26 20:11:34 +03:00
import Prologue
2016-01-06 19:56:58 +03:00
import qualified Data.OrderedMap as Map
2015-12-15 01:44:42 +03:00
import Test.Hspec
2015-12-15 01:42:57 +03:00
2015-12-15 01:48:59 +03:00
spec :: Spec
spec = parallel $ do
2015-12-15 01:47:42 +03:00
describe "difference" $ do
it "should return those elements of a not in b" $
Map.difference a b `shouldBe` Map.fromList [ ("a", 1) ]
2015-12-15 01:51:15 +03:00
it "is asymmetrical" $
2015-12-15 02:11:42 +03:00
Map.difference a b `shouldNotBe` Map.difference b a
2015-12-15 01:53:05 +03:00
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) ])
2015-12-15 01:53:05 +03:00
it "is asymmetrical" $
2015-12-15 02:15:56 +03:00
Map.union a b `shouldNotBe` Map.union b a
2015-12-15 02:13:19 +03:00
describe "unions" $ do
2015-12-15 02:16:22 +03:00
it "is equivalent to `union` for two maps" $
2015-12-15 02:13:19 +03:00
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
2015-12-15 01:54:22 +03:00
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) ]
2015-12-15 01:54:22 +03:00
it "is asymmetrical" $
Map.intersectionWith (-) a b `shouldNotBe` Map.intersectionWith (-) b a
2015-12-15 02:10:20 +03:00
describe "keys" $ do
it "should return all the keys in a map" $
Map.keys a `shouldBe` [ "a", "b", "c" ]
2015-12-15 02:18:40 +03:00
it "is ordered" $
Map.keys (Map.union b a) `shouldBe` [ "b", "c", "d", "a" ]
2015-12-15 01:51:15 +03:00
where a = Map.fromList [ ("a", 1), ("b", 2), ("c", 3) ]
2015-12-15 02:15:14 +03:00
b = Map.fromList [ ("b", -2), ("c", -3), ("d", -4) ]