mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
28 lines
954 B
Haskell
28 lines
954 B
Haskell
|
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
|