-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property test for added
lookupDefault
- Loading branch information
1 parent
25b7ef3
commit a1b0939
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ tests: | |
- hspec-expectations | ||
- directory | ||
- QuickCheck | ||
- quickcheck-instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module KeyMapSpec where | ||
|
||
import Data.Text (Text) | ||
import Test.Hspec | ||
import Test.QuickCheck | ||
import Test.QuickCheck.Instances () | ||
|
||
import qualified Data.HashMap.Internal.Strict as HM | ||
|
||
import qualified KeyMap as KM | ||
|
||
mapFirst :: (a->b) -> [(a,c)] -> [(b,c)] | ||
mapFirst _ [] = [] | ||
mapFirst f ((x,y) : rest) = (f x, y) : mapFirst f rest | ||
|
||
spec :: SpecWith () | ||
spec = | ||
describe "KeyMap" $ do | ||
it "lookupDefault matches the HashMap implementation" $ | ||
property $ \((fallback :: Text), key, mapping) -> | ||
let keyMapValue = KM.lookupDefault fallback (KM.fromText key) (KM.fromList $ mapFirst KM.fromText mapping) | ||
hashMapValue = HM.lookupDefault fallback key (HM.fromList mapping) | ||
in keyMapValue `shouldBe` hashMapValue |