-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_test.go
37 lines (28 loc) · 821 Bytes
/
map_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package grocery
import (
"encoding/json"
"testing"
)
func TestMap(t *testing.T) {
mapData := map[string]string{"a": "b", "c": "d"}
m := NewMap(mapData)
m.Map.Range(func(key, value interface{}) bool {
loadedValue, ok := mapData[key.(string)]
if !ok {
t.Errorf("map value FAILED, key %s does not exist", key)
return true
}
if value != loadedValue {
t.Errorf("map value FAILED, expected m[%s]=%s but got m[%s]=%s", key, value, key, loadedValue)
}
return true
})
if len(mapData) != m.Count() {
t.Errorf("map count FAILED, expected %d but got %d", len(mapData), m.Count())
}
expectedJSON, _ := json.Marshal(mapData)
json, _ := json.Marshal(m)
if string(json) != string(expectedJSON) {
t.Errorf("marshaljson FAILED, expected %s but got %s", string(expectedJSON), string(json))
}
}