-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdivision_test.go
166 lines (132 loc) · 3.16 KB
/
division_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package gb2260
import (
"strings"
"testing"
)
func Test_DivisionCountry(t *testing.T) {
// 110101 北京市/市辖区/东城区
gb := NewGB2260("")
division := gb.Get("110101")
if division == nil {
t.Error("division not exist")
}
if division.IsProvince() {
t.Log("expect not province, got province")
}
if division.IsPrefecture() {
t.Log("expect not prefecture, got prefecture")
}
if !division.IsCountry() {
t.Log("expect country, got not country")
}
var names []string
stacks := division.Stack()
for _, div := range stacks {
names = append(names, div.Name)
}
stackName := strings.Join(names, "/")
if stackName != "北京市/市辖区/东城区" {
t.Log("export 北京市/市辖区/东城区, got ", stackName)
}
}
func Test_DivisionPrefecture(t *testing.T) {
// 110101 北京市/东城区
gb := NewGB2260("")
division := gb.Get("110101")
if division == nil {
t.Error("division not exist")
}
if division.IsProvince() {
t.Log("expect not province, got province")
}
if !division.IsPrefecture() {
t.Log("expect prefecture, got not prefecture")
}
if division.IsCountry() {
t.Log("expect not country, got country")
}
var names []string
stacks := division.Stack()
for _, div := range stacks {
names = append(names, div.Name)
}
stackName := strings.Join(names, "/")
if stackName != "北京市/东城区" {
t.Log("export 北京市/东城区, got ", stackName)
}
}
func Test_DivisionProvince(t *testing.T) {
// 110000 北京市
gb := NewGB2260("")
division := gb.Get("110000")
if division == nil {
t.Error("division not exist")
}
if !division.IsProvince() {
t.Log("expect province, got not province")
}
if division.IsPrefecture() {
t.Log("expect not prefecture, got prefecture")
}
if division.IsCountry() {
t.Log("expect not country, got country")
}
var names []string
stacks := division.Stack()
for _, div := range stacks {
names = append(names, div.Name)
}
stackName := strings.Join(names, "/")
if stackName != "北京市" {
t.Log("export 北京市, got ", stackName)
}
}
func Test_Compare(t *testing.T) {
div := Division{Code: "110101", Name: "东城区", Revision: "201904"}
gb := NewGB2260("")
p := gb.Get("110101")
if p == nil {
t.Error("division not exist")
}
if !p.Equal(div) {
t.Log("expect equal division, got not equal")
}
div = Division{Code: "110000", Name: "东城区", Revision: "201904"}
p = gb.Get("110101")
if p == nil {
t.Error("division not exist")
}
if p.Equal(div) {
t.Log("expect not equal division, go equal")
}
}
func Test_Provinces(t *testing.T) {
gb := NewGB2260("")
p := gb.Provinces()
if p == nil {
t.Log("provinces is nil")
}
if len(p) != 34 {
t.Log("expect provinces length 34, but not")
}
}
func Test_Prefectures(t *testing.T) {
gb := NewGB2260("")
prefectures := gb.Prefectures("110101")
if prefectures == nil {
t.Error("prefectures is nil")
}
if len(prefectures) != 2 {
t.Log("expect prefectures length 2, but not")
}
}
func Test_Counties(t *testing.T) {
gb := NewGB2260("")
countries := gb.Counties("110101")
if countries == nil {
t.Error("prefectures is nil")
}
if len(countries) != 14 {
t.Log("expect counties length 14, but not")
}
}