1 module Strict.HUnit where
3 import Data.Function (($), id, const)
5 import Data.Monoid ((<>))
6 import Prelude (Integer, undefined)
7 import qualified Data.Map.Strict as Map
8 import qualified Data.Strict.Maybe as Strict
11 import Test.Tasty.HUnit
13 import Data.TreeMap.Strict (TreeMap(..), (<|))
14 import qualified Data.TreeMap.Strict as TreeMap
18 hunits = testGroup "Strict"
21 TreeMap.insert const ((0::Int)<|[]) () TreeMap.empty
22 @?= (TreeMap $ Map.fromList [ (0::Int, TreeMap.leaf ()) ])
24 TreeMap.insert const ((0::Int)<|[1]) () TreeMap.empty
28 [ (0::Int, TreeMap.Node
29 { TreeMap.node_value = Strict.Nothing
30 , TreeMap.node_size = 1
31 , TreeMap.node_descendants =
32 TreeMap.singleton ((1::Int)<|[]) ()
36 , testGroup "mapByDepthFirst"
37 [ testCase "[0, 0/1, 0/1/2, 1, 1/2/3]" $
38 TreeMap.mapByDepthFirst
39 (\descendants value ->
42 Strict.fromMaybe undefined $
45 (Strict.fromMaybe [] value)
46 (TreeMap.nodes descendants)
48 (TreeMap.fromList const
49 [ ((0::Integer)<|[], [0::Integer])
56 TreeMap.fromList const
57 [ ((0::Integer)<|[], [0,0,1,0,1,2])
58 , (0<|[1], [0,1,0,1,2])
65 TreeMap.mapByDepthFirst
66 (\descendants value ->
69 Strict.fromMaybe undefined $
72 (Strict.fromMaybe [] value)
73 (TreeMap.nodes descendants)
75 (TreeMap.fromList const
76 [ ((0::Integer)<|[0], [0::Integer,0])
79 TreeMap.fromList const
80 [ ((0::Integer)<|[], [0,0])
85 [ testCase "[0, 0/1, 0/1/2]" $
87 (TreeMap.fromList const
88 [ ((0::Integer)<|[], ())
94 [ ((0::Integer)<|[], ())
98 , testCase "[1, 1/2, 1/22, 1/2/3, 1/2/33, 11, 11/2, 11/2/3, 11/2/33]" $
100 (TreeMap.fromList const
101 [ ((1::Integer)<|[], ())
113 [ ((1::Integer)<|[], ())
124 , testGroup "lookupAlong"
125 [ testCase "0/1/2/3 [0, 0/1, 0/1/2, 0/1/2/3]" $
128 (TreeMap.fromList const
129 [ ((0::Integer)<|[], [0])
131 , (0<|[1,2], [0,1,2])
132 , (0<|[1,2,3], [0,1,2,3])
140 , testCase "0/1/2/3 [0, 0/1]" $
143 (TreeMap.fromList const
144 [ ((0::Integer)<|[], [0])