Skip to content

Commit 096617f

Browse files
committed
Might as well add a range test 🚂
1 parent 0038d6e commit 096617f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/map_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ func assertMapApi(t *testing.T, myMap map[string]int) {
6969
t.Error(`initial len of map should be 3`)
7070
}
7171

72+
var keys []string
73+
var values []int
74+
75+
for k, v := range myMap {
76+
keys = append(keys, k)
77+
values = append(values, v)
78+
}
79+
80+
if len(keys) != 3 || !containsString(keys, `test`) || !containsString(keys, `key`) || !containsString(keys, `charm`) {
81+
t.Error(`range did not contain the correct keys`)
82+
}
83+
84+
if len(values) != 3 || !containsInt(values, 0) || !containsInt(values, 1) || !containsInt(values, 2) {
85+
t.Error(`range did not contain the correct values`)
86+
}
87+
7288
if myMap[`test`] != 0 {
7389
t.Error(`value should be 0`)
7490
}
@@ -126,3 +142,21 @@ func assertMapApi(t *testing.T, myMap map[string]int) {
126142
t.Error(`copy should be equivalent`)
127143
}
128144
}
145+
146+
func containsInt(s []int, e int) bool {
147+
for _, a := range s {
148+
if a == e {
149+
return true
150+
}
151+
}
152+
return false
153+
}
154+
155+
func containsString(s []string, e string) bool {
156+
for _, a := range s {
157+
if a == e {
158+
return true
159+
}
160+
}
161+
return false
162+
}

0 commit comments

Comments
 (0)