mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
c4cdacf989
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3362 Co-authored-by: Chris Parks <592078+cdparks@users.noreply.github.com> GitOrigin-RevId: 802c099c26ff024e6cf594ea0317480e260486e9
46 lines
1.4 KiB
Haskell
46 lines
1.4 KiB
Haskell
module Data.HashMap.Strict.ExtendedSpec
|
|
( spec,
|
|
)
|
|
where
|
|
|
|
import Data.HashMap.Strict.Extended qualified as Map
|
|
import Hasura.Prelude
|
|
import Test.Hspec
|
|
import Test.QuickCheck
|
|
|
|
spec :: Spec
|
|
spec = describe "isInverseOf" $ do
|
|
it "is satisfied by maps with the same unique keys as values" $
|
|
property $
|
|
\(xs :: [Int]) -> do
|
|
let m = Map.fromList $ zip xs xs
|
|
m `Map.isInverseOf` m
|
|
|
|
it "is satisfied by maps with swapped unique keys and values" $
|
|
property $
|
|
\(vals :: [Int]) -> do
|
|
let keys = show <$> vals
|
|
let forward = Map.fromList $ zip keys vals
|
|
let backward = Map.fromList $ zip vals keys
|
|
forward `Map.isInverseOf` backward
|
|
|
|
it "fails when different keys map to one value" $
|
|
property $
|
|
\(NonNegative (x :: Int)) (Positive (n :: Int)) -> do
|
|
let keys = take (n + 2) [x ..]
|
|
let vals = even <$> keys
|
|
let forward = Map.fromList $ zip keys vals
|
|
let backward = Map.fromList $ zip vals keys
|
|
not $ forward `Map.isInverseOf` backward
|
|
|
|
it "passes some trivial examples as a smoke test" $ do
|
|
let fwd = Map.fromList @Int @Bool
|
|
let bwd = Map.fromList @Bool @Int
|
|
and
|
|
[ fwd [] `Map.isInverseOf` bwd [],
|
|
not $ fwd [(1, True)] `Map.isInverseOf` bwd [],
|
|
not $ fwd [] `Map.isInverseOf` bwd [(True, 1)],
|
|
fwd [(1, True)] `Map.isInverseOf` bwd [(True, 1)],
|
|
not $ fwd [(2, True)] `Map.isInverseOf` bwd [(True, 1)]
|
|
]
|