@@ -135,79 +135,3 @@ from_list(List) when is_list(List) ->
135135-spec keys (gb_trees :tree (K ,_V )) -> [ec_dictionary :key (K )].
136136keys (Data ) ->
137137 gb_trees :keys (Data ).
138-
139- % %%===================================================================
140- % %% Tests
141- % %%===================================================================
142-
143-
144- -ifdef (TEST ).
145- -include_lib (" eunit/include/eunit.hrl" ).
146-
147- % % For me unit testing initially is about covering the obvious case. A
148- % % check to make sure that what you expect the tested functionality to
149- % % do, it actually does. As time goes on and people detect bugs you
150- % % add tests for those specific problems to the unit test suit.
151- % %
152- % % However, when getting started you can only test your basic
153- % % expectations. So here are the expectations I have for the add
154- % % functionality.
155- % %
156- % % 1) I can put arbitrary terms into the dictionary as keys
157- % % 2) I can put arbitrary terms into the dictionary as values
158- % % 3) When I put a value in the dictionary by a key, I can retrieve
159- % % that same value
160- % % 4) When I put a different value in the dictionary by key it does
161- % % not change other key value pairs.
162- % % 5) When I update a value the new value in available by the new key
163- % % 6) When a value does not exist a not found exception is created
164-
165- add_test () ->
166- Dict0 = ec_dictionary :new (ec_gb_trees ),
167-
168- Key1 = foo ,
169- Key2 = [1 , 3 ],
170- Key3 = {" super" },
171- Key4 = <<" fabulous" >>,
172- Key5 = {" Sona" , 2 , <<" Zuper" >>},
173-
174- Value1 = Key5 ,
175- Value2 = Key4 ,
176- Value3 = Key2 ,
177- Value4 = Key3 ,
178- Value5 = Key1 ,
179-
180- Dict01 = ec_dictionary :add (Key1 , Value1 , Dict0 ),
181- Dict02 = ec_dictionary :add (Key3 , Value3 ,
182- ec_dictionary :add (Key2 , Value2 ,
183- Dict01 )),
184- Dict1 =
185- ec_dictionary :add (Key5 , Value5 ,
186- ec_dictionary :add (Key4 , Value4 ,
187- Dict02 )),
188-
189- ? assertMatch (Value1 , ec_dictionary :get (Key1 , Dict1 )),
190- ? assertMatch (Value2 , ec_dictionary :get (Key2 , Dict1 )),
191- ? assertMatch (Value3 , ec_dictionary :get (Key3 , Dict1 )),
192- ? assertMatch (Value4 , ec_dictionary :get (Key4 , Dict1 )),
193- ? assertMatch (Value5 , ec_dictionary :get (Key5 , Dict1 )),
194-
195-
196- Dict2 = ec_dictionary :add (Key3 , Value5 ,
197- ec_dictionary :add (Key2 , Value4 , Dict1 )),
198-
199-
200- ? assertMatch (Value1 , ec_dictionary :get (Key1 , Dict2 )),
201- ? assertMatch (Value4 , ec_dictionary :get (Key2 , Dict2 )),
202- ? assertMatch (Value5 , ec_dictionary :get (Key3 , Dict2 )),
203- ? assertMatch (Value4 , ec_dictionary :get (Key4 , Dict2 )),
204- ? assertMatch (Value5 , ec_dictionary :get (Key5 , Dict2 )),
205-
206-
207- ? assertThrow (not_found , ec_dictionary :get (should_blow_up , Dict2 )),
208- ? assertThrow (not_found , ec_dictionary :get (" This should blow up too" ,
209- Dict2 )).
210-
211-
212-
213- -endif .
0 commit comments