1 {-# LANGUAGE NamedFieldPuns #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE ScopedTypeVariables #-}
4 {-# LANGUAGE TupleSections #-}
7 import Data.Function (($), id, const)
9 import qualified Data.Map.Strict as Map
10 import Data.Monoid ((<>))
11 import qualified Data.Strict.Maybe as Strict
12 import Prelude (Integer, undefined)
14 import Test.Tasty.HUnit
16 import Data.TreeMap.Strict ((<|))
17 import Data.TreeMap.Strict (TreeMap(..))
18 import qualified Data.TreeMap.Strict as TreeMap
22 tests = testGroup "Strict"
25 TreeMap.insert const ((0::Int)<|[]) () TreeMap.empty
26 @?= (TreeMap $ Map.fromList [ (0::Int, TreeMap.leaf ()) ])
28 TreeMap.insert const ((0::Int)<|[1]) () TreeMap.empty
32 [ (0::Int, TreeMap.Node
33 { TreeMap.node_value = Strict.Nothing
34 , TreeMap.node_size = 1
35 , TreeMap.node_descendants =
36 TreeMap.singleton ((1::Int)<|[]) ()
40 , testGroup "mapByDepthFirst"
41 [ testCase "[0, 0/1, 0/1/2, 1, 1/2/3]" $
42 TreeMap.mapByDepthFirst
43 (\descendants value ->
46 Strict.fromMaybe undefined $
49 (Strict.fromMaybe [] value)
50 (TreeMap.nodes descendants)
52 (TreeMap.fromList const
53 [ ((0::Integer)<|[], [0::Integer])
60 TreeMap.fromList const
61 [ ((0::Integer)<|[], [0,0,1,0,1,2])
62 , (0<|[1], [0,1,0,1,2])
69 TreeMap.mapByDepthFirst
70 (\descendants value ->
73 Strict.fromMaybe undefined $
76 (Strict.fromMaybe [] value)
77 (TreeMap.nodes descendants)
79 (TreeMap.fromList const
80 [ ((0::Integer)<|[0], [0::Integer,0])
83 TreeMap.fromList const
84 [ ((0::Integer)<|[], [0,0])
89 [ testCase "[0, 0/1, 0/1/2]" $
91 (TreeMap.fromList const
92 [ ((0::Integer)<|[], ())
98 [ ((0::Integer)<|[], ())
102 , testCase "[1, 1/2, 1/22, 1/2/3, 1/2/33, 11, 11/2, 11/2/3, 11/2/33]" $
104 (TreeMap.fromList const
105 [ ((1::Integer)<|[], ())
117 [ ((1::Integer)<|[], ())
128 , testGroup "lookupAlong"
129 [ testCase "0/1/2/3 [0, 0/1, 0/1/2, 0/1/2/3]" $
132 (TreeMap.fromList const
133 [ ((0::Integer)<|[], [0])
135 , (0<|[1,2], [0,1,2])
136 , (0<|[1,2,3], [0,1,2,3])
144 , testCase "0/1/2/3 [0, 0/1]" $
147 (TreeMap.fromList const
148 [ ((0::Integer)<|[], [0])