graphql-engine/server/src-test/Data/TrieSpec.hs
Tom Harding 7e334e08a4 Import HashMap, not HM, Map, M...
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8947
GitOrigin-RevId: 18e52c928e1df535579e2077b4af6c2ce92bdcef
2023-04-26 15:43:44 +00:00

28 lines
966 B
Haskell

module Data.TrieSpec (spec) where
import Data.HashMap.Strict qualified as HashMap
import Data.Trie qualified as T
import Hasura.Prelude
import Hasura.QuickCheck.Instances ()
import Test.Hspec
import Test.Hspec.QuickCheck
type TestTrie = T.Trie String [Int]
spec :: Spec
spec = describe "Trie" $ do
describe "insert" $ do
prop "insert a path into an empty trie" $ \p v -> do
let expected = T.singleton p v :: TestTrie
T.insert p v T.empty `shouldBe` expected
prop "insert a singleton path into an empty trie" $ \pc v -> do
let expected = T.Trie (HashMap.singleton pc (T.Trie mempty (Just v))) Nothing :: TestTrie
T.insert [pc] v T.empty `shouldBe` expected
prop "insertion is idempotent" $ \p v (t :: TestTrie) -> do
T.insert p v (T.insert p v t) `shouldBe` T.insert p v t
prop "insertion with mappend monoid equivalence" $ \p v (t :: TestTrie) -> do
T.insertWith (<>) p v t `shouldBe` T.singleton p v <> t