@@ -24,8 +24,8 @@ fn map_any[T](items []T, cb fn (item T) bool) bool {
2424 return false
2525}
2626
27- fn test_map_values_method () {
28- // testing map[int]stirng
27+ fn test_values_method () {
28+ // testing map[int]string
2929 items_1 := {
3030 1 : 'item_1'
3131 2 : 'item_2'
@@ -84,7 +84,7 @@ fn test_map_values_method() {
8484 })
8585}
8686
87- fn test_map_values_method_with_generic_constraints () {
87+ fn test_values_method_with_generic_constraints () {
8888 // test with string constraint
8989 string_map := {
9090 'first' : 'hello'
@@ -106,7 +106,17 @@ fn test_map_values_method_with_generic_constraints() {
106106 assert int_result.contains (2 )
107107}
108108
109- fn test_map_keys_method () {
109+ fn test_keys_method () {
110+ // testing map[int]string keys
111+ items_1 := {
112+ 1 : 'item_1'
113+ 2 : 'item_2'
114+ 3 : 'item_3'
115+ }
116+ for key in items_1 .keys () {
117+ assert 'item_${key }' == items_1 [key]
118+ }
119+
110120 // testing map[string]int keys
111121 items_2 := {
112122 'item_1' : 1
@@ -147,7 +157,7 @@ fn test_map_keys_method() {
147157 assert point_keys.contains ('unit_y' )
148158}
149159
150- fn test_map_keys_method_with_generic_constraints () {
160+ fn test_keys_method_with_generic_constraints () {
151161 // test with string values
152162 string_map := {
153163 'first' : 'hello'
@@ -176,9 +186,51 @@ fn test_map_keys_method_with_generic_constraints() {
176186 assert empty_keys.len == 0
177187}
178188
189+ fn test_direct_map_access () {
190+ // testing map[int]string
191+ items_1 := {
192+ 1 : 'one'
193+ 2 : 'two'
194+ 3 : 'three'
195+ }
196+ assert items_1 [1 ] == 'one'
197+ assert items_1 [2 ] == 'two'
198+ assert items_1 [3 ] == 'three'
199+
200+ // testing map[string]int
201+ items_2 := {
202+ 'one' : 1
203+ 'two' : 2
204+ 'three' : 3
205+ }
206+ assert items_2 ['one' ] == 1
207+ assert items_2 ['two' ] == 2
208+ assert items_2 ['three' ] == 3
209+ }
210+
211+ fn test_map_len () {
212+ // testing on the fly maps
213+ items_1 := {
214+ 'one' : 1
215+ 'two' : 2
216+ }
217+ assert items_1 .len == 2
218+
219+ // testing empty map length
220+ mut items_2 := map [string ]int {}
221+ assert items_2 .len == 0
222+
223+ // testing dynamic addition map length
224+ items_2 ['one' ] = 1
225+ items_2 ['two' ] = 2
226+ assert items_2 .len == 2
227+ }
228+
179229fn main () {
180- test_map_values_method ()
181- test_map_values_method_with_generic_constraints ()
182- test_map_keys_method ()
183- test_map_keys_method_with_generic_constraints ()
230+ test_values_method ()
231+ test_values_method_with_generic_constraints ()
232+ test_keys_method ()
233+ test_keys_method_with_generic_constraints ()
234+ test_direct_map_access ()
235+ test_map_len ()
184236}
0 commit comments