1 {-# LANGUAGE NamedFieldPuns #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE ScopedTypeVariables #-}
4 {-# LANGUAGE TupleSections #-}
5 module Strict.Test where
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 qualified Data.TreeMap.Strict as TreeMap
21 tests = testGroup "Strict"
24 TreeMap.insert const ((0::Int)<|[]) () TreeMap.empty
25 @?= (TreeMap.TreeMap $ Map.fromList [ (0::Int, TreeMap.leaf ()) ])
27 TreeMap.insert const ((0::Int)<|[1]) () TreeMap.empty
31 [ (0::Int, TreeMap.Node
32 { TreeMap.node_value = Strict.Nothing
33 , TreeMap.node_size = 1
34 , TreeMap.node_descendants =
35 TreeMap.singleton ((1::Int)<|[]) ()
39 , testGroup "map_by_depth_first"
40 [ testCase "[0, 0/1, 0/1/2, 1, 1/2/3]" $
41 TreeMap.map_by_depth_first
42 (\descendants value ->
45 Strict.fromMaybe undefined $
48 (Strict.fromMaybe [] value)
49 (TreeMap.nodes descendants)
51 (TreeMap.from_List const
52 [ ((0::Integer)<|[], [0::Integer])
59 TreeMap.from_List const
60 [ ((0::Integer)<|[], [0,0,1,0,1,2])
61 , (0<|[1], [0,1,0,1,2])
68 TreeMap.map_by_depth_first
69 (\descendants value ->
72 Strict.fromMaybe undefined $
75 (Strict.fromMaybe [] value)
76 (TreeMap.nodes descendants)
78 (TreeMap.from_List const
79 [ ((0::Integer)<|[0], [0::Integer,0])
82 TreeMap.from_List const
83 [ ((0::Integer)<|[], [0,0])
88 [ testCase "[0, 0/1, 0/1/2]" $
90 (TreeMap.from_List const
91 [ ((0::Integer)<|[], ())
97 [ ((0::Integer)<|[], ())
101 , testCase "[1, 1/2, 1/22, 1/2/3, 1/2/33, 11, 11/2, 11/2/3, 11/2/33]" $
103 (TreeMap.from_List const
104 [ ((1::Integer)<|[], ())
116 [ ((1::Integer)<|[], ())
127 , testGroup "find_along"
128 [ testCase "0/1/2/3 [0, 0/1, 0/1/2, 0/1/2/3]" $
131 (TreeMap.from_List const
132 [ ((0::Integer)<|[], [0])
134 , (0<|[1,2], [0,1,2])
135 , (0<|[1,2,3], [0,1,2,3])
143 , testCase "0/1/2/3 [0, 0/1]" $
146 (TreeMap.from_List const
147 [ ((0::Integer)<|[], [0])