]> Git — Sourcephile - haskell/treemap.git/blob - test/Strict/HUnit.hs
Clean up test/.
[haskell/treemap.git] / test / Strict / HUnit.hs
1 module Strict.HUnit where
2
3 import Data.Function (($), id, const)
4 import Data.Int (Int)
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
9
10 import Test.Tasty
11 import Test.Tasty.HUnit
12
13 import Data.TreeMap.Strict (TreeMap(..), (<|))
14 import qualified Data.TreeMap.Strict as TreeMap
15
16
17 hunits :: TestTree
18 hunits = testGroup "Strict"
19 [ testGroup "insert"
20 [ testCase "[] 0" $
21 TreeMap.insert const ((0::Int)<|[]) () TreeMap.empty
22 @?= (TreeMap $ Map.fromList [ (0::Int, TreeMap.leaf ()) ])
23 , testCase "[] 0/1" $
24 TreeMap.insert const ((0::Int)<|[1]) () TreeMap.empty
25 @?=
26 (TreeMap $
27 Map.fromList
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)<|[]) ()
33 })
34 ])
35 ]
36 , testGroup "mapByDepthFirst"
37 [ testCase "[0, 0/1, 0/1/2, 1, 1/2/3]" $
38 TreeMap.mapByDepthFirst
39 (\descendants value ->
40 Map.foldl'
41 (\acc v -> (<>) acc $
42 Strict.fromMaybe undefined $
43 TreeMap.node_value v
44 )
45 (Strict.fromMaybe [] value)
46 (TreeMap.nodes descendants)
47 )
48 (TreeMap.fromList const
49 [ ((0::Integer)<|[], [0::Integer])
50 , (0<|[1], [0,1])
51 , (0<|[1,2], [0,1,2])
52 , (1<|[], [1])
53 , (1<|[2,3], [1,2,3])
54 ])
55 @?=
56 TreeMap.fromList const
57 [ ((0::Integer)<|[], [0,0,1,0,1,2])
58 , (0<|[1], [0,1,0,1,2])
59 , (0<|[1,2], [0,1,2])
60 , (1<|[], [1,1,2,3])
61 , (1<|[2], [1,2,3])
62 , (1<|[2,3], [1,2,3])
63 ]
64 , testCase "[0/0]" $
65 TreeMap.mapByDepthFirst
66 (\descendants value ->
67 Map.foldl'
68 (\acc v -> (<>) acc $
69 Strict.fromMaybe undefined $
70 TreeMap.node_value v
71 )
72 (Strict.fromMaybe [] value)
73 (TreeMap.nodes descendants)
74 )
75 (TreeMap.fromList const
76 [ ((0::Integer)<|[0], [0::Integer,0])
77 ])
78 @?=
79 TreeMap.fromList const
80 [ ((0::Integer)<|[], [0,0])
81 , (0<|[0], [0,0])
82 ]
83 ]
84 , testGroup "flatten"
85 [ testCase "[0, 0/1, 0/1/2]" $
86 TreeMap.flatten id
87 (TreeMap.fromList const
88 [ ((0::Integer)<|[], ())
89 , (0<|[1], ())
90 , (0<|[1,2], ())
91 ])
92 @?=
93 Map.fromList
94 [ ((0::Integer)<|[], ())
95 , (0<|[1], ())
96 , (0<|[1,2], ())
97 ]
98 , testCase "[1, 1/2, 1/22, 1/2/3, 1/2/33, 11, 11/2, 11/2/3, 11/2/33]" $
99 TreeMap.flatten id
100 (TreeMap.fromList const
101 [ ((1::Integer)<|[], ())
102 , (1<|[2], ())
103 , (1<|[22], ())
104 , (1<|[2,3], ())
105 , (1<|[2,33], ())
106 , (11<|[], ())
107 , (11<|[2], ())
108 , (11<|[2,3], ())
109 , (11<|[2,33], ())
110 ])
111 @?=
112 Map.fromList
113 [ ((1::Integer)<|[], ())
114 , (1<|[2], ())
115 , (1<|[22], ())
116 , (1<|[2,3], ())
117 , (1<|[2,33], ())
118 , (11<|[], ())
119 , (11<|[2], ())
120 , (11<|[2,3], ())
121 , (11<|[2,33], ())
122 ]
123 ]
124 , testGroup "lookupAlong"
125 [ testCase "0/1/2/3 [0, 0/1, 0/1/2, 0/1/2/3]" $
126 TreeMap.lookupAlong
127 (0<|[1,2,3])
128 (TreeMap.fromList const
129 [ ((0::Integer)<|[], [0])
130 , (0<|[1], [0,1])
131 , (0<|[1,2], [0,1,2])
132 , (0<|[1,2,3], [0,1,2,3])
133 ])
134 @?=
135 [ [0::Integer]
136 , [0,1]
137 , [0,1,2]
138 , [0,1,2,3]
139 ]
140 , testCase "0/1/2/3 [0, 0/1]" $
141 TreeMap.lookupAlong
142 (0<|[1,2,3])
143 (TreeMap.fromList const
144 [ ((0::Integer)<|[], [0])
145 , (0<|[1], [0,1])
146 ])
147 @?=
148 [ [0::Integer]
149 , [0,1]
150 ]
151 ]
152 ]