graphql-engine/server/src-test/Data/HashMap/Strict/ExtendedSpec.hs
Auke Booij c4cdacf989 First attempt at deduplicating permission filters
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
2022-02-03 16:14:44 +00:00

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)]
]