2015-12-15 01:42:57 +03:00
|
|
|
module OrderedMapSpec where
|
|
|
|
|
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
|
2016-01-05 18:38:51 +03:00
|
|
|
spec = parallel $ do
|
2015-12-15 01:47:42 +03:00
|
|
|
describe "difference" $ do
|
|
|
|
it "should return those elements of a not in b" $
|
2016-01-05 18:41:26 +03:00
|
|
|
Map.difference a b `shouldBe` Map.fromList [ ("a", 1) ]
|
2015-12-15 01:51:15 +03:00
|
|
|
|
2016-01-05 18:41:40 +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" $
|
2016-01-05 18:41:26 +03:00
|
|
|
Map.union a b `shouldBe` Map.fromList (Map.toList a ++ [ ("d", -4) ])
|
2015-12-15 01:53:05 +03:00
|
|
|
|
2016-01-05 18:41:40 +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
|
|
|
|
|
2015-12-15 02:17:48 +03:00
|
|
|
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" $
|
2016-01-05 18:41:26 +03:00
|
|
|
Map.intersectionWith (-) a b `shouldBe` Map.fromList [ ("b", 4), ("c", 6) ]
|
2015-12-15 01:54:22 +03:00
|
|
|
|
2016-01-05 18:41:40 +03:00
|
|
|
it "is asymmetrical" $
|
2015-12-15 02:20:21 +03:00
|
|
|
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) ]
|