Skip to content

Commit

Permalink
Move tree spec module
Browse files Browse the repository at this point in the history
  • Loading branch information
felko committed Apr 21, 2020
1 parent 67e5a1c commit a71f23c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 66 deletions.
58 changes: 58 additions & 0 deletions test/Neuron/Util/TreeSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{-# LANGUAGE NoImplicitPrelude #-}

module Neuron.Util.TreeSpec
( spec,
)
where

import Data.Tree (Forest, Tree (..))
import qualified Neuron.Util.Tree as Z
import Relude
import System.FilePath ((</>))
import Test.Hspec

spec :: Spec
spec = do
describe "Path tree" $ do
context "Tree building" $ do
forM_ treeCases $ \(name, paths, tree) -> do
it name $ do
Z.mkTreeFromPaths paths `shouldBe` tree
context "Tree folding" $ do
forM_ foldingCases $ \(name, tree, folded) -> do
it name $ do
let mergePaths (p, _) (p', b') = (p </> p', b')
res = fmap fst $ Z.foldTreeOnWith snd mergePaths tree
res `shouldBe` folded

treeCases :: [(String, [[String]], Forest String)]
treeCases =
[ ( "works on one level",
[["journal"], ["science"]],
[Node "journal" [], Node "science" []]
),
( "groups paths with common prefix",
[["math", "algebra"], ["math", "calculus"]],
[Node "math" [Node "algebra" [], Node "calculus" []]]
),
( "ignores tag when there is also tag/subtag",
[["math"], ["math", "algebra"]],
[Node "math" [Node "algebra" []]]
)
]

foldingCases :: [(String, Tree (String, Bool), Tree String)]
foldingCases =
[ ( "folds tree on one level",
Node ("math", True) [Node ("note", False) []],
Node "math/note" []
),
( "folds across multiple levels",
Node ("math", True) [Node ("algebra", True) [Node ("note", False) []]],
Node "math/algebra/note" []
),
( "does not fold tree when the predicate is false",
Node ("math", False) [Node ("note", False) []],
Node "math" [Node "note" []]
)
]
66 changes: 0 additions & 66 deletions test/Neuron/Zettelkasten/Tag/TreeSpec.hs

This file was deleted.

0 comments on commit a71f23c

Please sign in to comment.