graphql-engine/server/src-test/Data/TrieSpec.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
954 B
Haskell
Raw Normal View History

module Data.TrieSpec (spec) where
import Data.HashMap.Strict qualified as M
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 (M.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