-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadcode_test.go
40 lines (33 loc) · 986 Bytes
/
adcode_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
38
39
40
package location
import (
"testing"
)
func TestCode(t *testing.T) {
testdatas := [][3]string{
[3]string{"山东省", "370000", ""},
[3]string{"临沂市", "371300", "0539"},
[3]string{"沂水县", "371323", ""},
[3]string{"北京市", "110000", "010"},
}
for _, testdate := range testdatas {
adcode := GetAdcode(testdate[0])
if adcode != testdate[1] {
t.Fatal(`[GetAdcode] expect "` + testdate[1] + `", but get "` + adcode + `"`)
}
name := GetNameByAdcode(testdate[1])
if name != testdate[0] {
t.Fatal(`[GetNameByAdcode] expect "` + testdate[0] + `", but get "` + name + `"`)
}
//county
if testdate[2] != "" {
citycode := GetCitycode(testdate[0])
if citycode != testdate[2] {
t.Fatal(`[GetCitycode] expect "` + testdate[2] + `", but get "` + citycode + `"`)
}
name := GetNameByCitycode(testdate[2])
if name != testdate[0] {
t.Fatal(`[GetNameByCitycode] expect "` + testdate[0] + `", but get "` + name + `"`)
}
}
}
}