-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnormalizer_test.go
304 lines (291 loc) · 17.5 KB
/
normalizer_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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package gokenall
import (
"reflect"
"testing"
)
func Test_normalizer_push(t *testing.T) {
type args struct {
p *JapanZipCode
}
tests := []struct {
name string
normer *normalizer
args args
}{
{"no error", newNormalizer(), args{&JapanZipCode{}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.normer.push(tt.args.p)
})
}
}
func Test_normalizer_canPop(t *testing.T) {
n1 := newNormalizer()
n2 := newNormalizer()
n2.outputs = append(n2.outputs, &JapanZipCode{})
tests := []struct {
name string
normer *normalizer
want bool
}{
{"false", n1, false},
{"true", n2, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.normer.canPop(); got != tt.want {
t.Errorf("normalizer.canPop() = %v, want %v", got, tt.want)
}
})
}
}
func Test_normalizer_pop(t *testing.T) {
z1 := &JapanZipCode{PrefCode: "01"}
z2 := &JapanZipCode{PrefCode: "02"}
n1 := newNormalizer()
n2 := newNormalizer()
n2.outputs = append(n2.outputs, z1)
n2.outputs = append(n2.outputs, z2)
tests := []struct {
name string
normer *normalizer
want *JapanZipCode
}{
{"", n1, nil},
{"", n2, z1},
{"", n2, z2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.normer.pop(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("normalizer.pop() = %v, want %v", got, tt.want)
}
})
}
}
func Test_normalizer_normalize(t *testing.T) {
beforeAfter := [][][]string{
{
{`01101,"060 ","0600000","ホッカイドウ","サッポロシチュウオウク","イカニケイサイガナイバアイ","北海道","札幌市中央区","以下に掲載がない場合",0,0,0,0,0,0`},
{`01101,"060 ","0600000","ホッカイドウ","サッポロシチュウオウク","","北海道","札幌市中央区","",0,0,0,0,0,0`},
},
{
{`08546,"30604","3060433","イバラキケン","サシマグンサカイマチ","サカイマチノツギニバンチガクルバアイ","茨城県","猿島郡境町","境町の次に番地がくる場合",0,0,0,0,0,0`},
{`08546,"30604","3060433","イバラキケン","サシマグンサカイマチ","","茨城県","猿島郡境町","",0,0,0,0,0,0`},
},
{
{`13362,"10003","1000301","トウキョウト","トシマムラ","トシマムライチエン","東京都","利島村","利島村一円",0,0,0,0,0,0`},
{`13362,"10003","1000301","トウキョウト","トシマムラ","","東京都","利島村","",0,0,0,0,0,0`},
},
{
{`25443,"52203","5220317","シガケン","イヌカミグンタガチョウ","イチエン","滋賀県","犬上郡多賀町","一円",0,0,0,0,0,0`},
{`25443,"52203","5220317","シガケン","イヌカミグンタガチョウ","イチエン","滋賀県","犬上郡多賀町","一円",0,0,0,0,0,0`},
},
{
{`26103,"606 ","6060017","キョウトフ","キョウトシサキョウク","イワクラアグラチョウ(ソノタ)","京都府","京都市左京区","岩倉上蔵町(その他)",1,0,0,0,0,0`},
{`26103,"606 ","6060017","キョウトフ","キョウトシサキョウク","イワクラアグラチョウ","京都府","京都市左京区","岩倉上蔵町",1,0,0,0,0,0`},
},
{
{`27119,"545 ","5456090","オオサカフ","オオサカシアベノク","アベノスジアベノハルカス(チカイ・カイソウフメイ)","大阪府","大阪市阿倍野区","阿倍野筋あべのハルカス(地階・階層不明)",0,0,0,0,0,0`},
{`27119,"545 ","5456090","オオサカフ","オオサカシアベノク","アベノスジアベノハルカス","大阪府","大阪市阿倍野区","阿倍野筋あべのハルカス",0,0,0,0,0,0`},
},
{
{`27119,"545 ","5450052","オオサカフ","オオサカシアベノク","アベノスジ(ツギノビルヲノゾク)","大阪府","大阪市阿倍野区","阿倍野筋(次のビルを除く)",0,0,1,0,0,0`},
{`27119,"545 ","5450052","オオサカフ","オオサカシアベノク","アベノスジ","大阪府","大阪市阿倍野区","阿倍野筋",0,0,1,0,0,0`},
},
{
{`27119,"545 ","5456060","オオサカフ","オオサカシアベノク","アベノスジアベノハルカス(60カイ)","大阪府","大阪市阿倍野区","阿倍野筋あべのハルカス(60階)",0,0,0,0,0,0`},
{`27119,"545 ","5456060","オオサカフ","オオサカシアベノク","アベノスジアベノハルカス60カイ","大阪府","大阪市阿倍野区","阿倍野筋あべのハルカス60階",0,0,0,0,0,0`},
},
{
{
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ(1-6チョウメ)","大阪府","大阪市北区","天神橋(1~6丁目)",1,0,1,0,0,0`,
},
{
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ1チョウメ","大阪府","大阪市北区","天神橋1丁目",1,0,1,0,0,0`,
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ2チョウメ","大阪府","大阪市北区","天神橋2丁目",1,0,1,0,0,0`,
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ3チョウメ","大阪府","大阪市北区","天神橋3丁目",1,0,1,0,0,0`,
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ4チョウメ","大阪府","大阪市北区","天神橋4丁目",1,0,1,0,0,0`,
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ5チョウメ","大阪府","大阪市北区","天神橋5丁目",1,0,1,0,0,0`,
`27127,"530 ","5300041","オオサカフ","オオサカシキタク","テンジンバシ6チョウメ","大阪府","大阪市北区","天神橋6丁目",1,0,1,0,0,0`,
},
},
{
{
`27127,"531 ","5310041","オオサカフ","オオサカシキタク","テンジンバシ(7、8チョウメ)","大阪府","大阪市北区","天神橋(7、8丁目)",1,0,1,0,0,0`,
},
{
`27127,"531 ","5310041","オオサカフ","オオサカシキタク","テンジンバシ7チョウメ","大阪府","大阪市北区","天神橋7丁目",1,0,1,0,0,0`,
`27127,"531 ","5310041","オオサカフ","オオサカシキタク","テンジンバシ8チョウメ","大阪府","大阪市北区","天神橋8丁目",1,0,1,0,0,0`,
},
},
{
{
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン(1-7バンチ)","北海道","有珠郡壮瞥町","洞爺湖温泉(1~7番地)",1,0,0,0,0,0`,
},
{
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン1バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉1番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン2バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉2番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン3バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉3番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン4バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉4番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン5バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉5番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン6バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉6番地",1,0,0,0,0,0`,
`01575,"04957","0495731","ホッカイドウ","ウスグンソウベツチョウ","トウヤコオンセン7バンチ","北海道","有珠郡壮瞥町","洞爺湖温泉7番地",1,0,0,0,0,0`,
},
},
{
{
`01604,"05922","0592253","ホッカイドウ","ニイカップグンニイカップチョウ","オオカリベ(436、516、567バンチ)","北海道","新冠郡新冠町","大狩部(436、516、567番地)",1,0,0,0,0,0`,
},
{
`01604,"05922","0592253","ホッカイドウ","ニイカップグンニイカップチョウ","オオカリベ436バンチ","北海道","新冠郡新冠町","大狩部436番地",1,0,0,0,0,0`,
`01604,"05922","0592253","ホッカイドウ","ニイカップグンニイカップチョウ","オオカリベ516バンチ","北海道","新冠郡新冠町","大狩部516番地",1,0,0,0,0,0`,
`01604,"05922","0592253","ホッカイドウ","ニイカップグンニイカップチョウ","オオカリベ567バンチ","北海道","新冠郡新冠町","大狩部567番地",1,0,0,0,0,0`,
},
},
{
{
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ(1-7バン)","大分県","大分市","高城西町(1~7番)",1,0,0,0,0,0`,
},
{
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ1バン","大分県","大分市","高城西町1番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ2バン","大分県","大分市","高城西町2番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ3バン","大分県","大分市","高城西町3番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ4バン","大分県","大分市","高城西町4番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ5バン","大分県","大分市","高城西町5番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ6バン","大分県","大分市","高城西町6番",1,0,0,0,0,0`,
`44201,"870 ","8700923","オオイタケン","オオイタシ","タカジョウニシマチ7バン","大分県","大分市","高城西町7番",1,0,0,0,0,0`,
},
},
{
{
`01214,"09845","0984581","ホッカイドウ","ワッカナイシ","バッカイムラ(カミユウチ、シモユウチ、ユウクル、オネトマナイ)","北海道","稚内市","抜海村(上勇知、下勇知、夕来、オネトマナイ)",1,0,0,0,0,0`,
},
{
`01214,"09845","0984581","ホッカイドウ","ワッカナイシ","バッカイムラカミユウチ","北海道","稚内市","抜海村上勇知",1,0,0,0,0,0`,
`01214,"09845","0984581","ホッカイドウ","ワッカナイシ","バッカイムラシモユウチ","北海道","稚内市","抜海村下勇知",1,0,0,0,0,0`,
`01214,"09845","0984581","ホッカイドウ","ワッカナイシ","バッカイムラユウクル","北海道","稚内市","抜海村夕来",1,0,0,0,0,0`,
`01214,"09845","0984581","ホッカイドウ","ワッカナイシ","バッカイムラオネトマナイ","北海道","稚内市","抜海村オネトマナイ",1,0,0,0,0,0`,
},
},
{
{
`01104,"003 ","0030022","ホッカイドウ","サッポロシシロイシク","ナンゴウドオリ(ミナミ)","北海道","札幌市白石区","南郷通(南)",1,0,0,0,0,0`,
},
{
`01104,"003 ","0030022","ホッカイドウ","サッポロシシロイシク","ナンゴウドオリミナミ","北海道","札幌市白石区","南郷通南",1,0,0,0,0,0`,
},
},
{
{
`04101,"980 ","9800065","ミヤギケン","センダイシアオバク","ツチトイ(1チョウメ<11ヲノゾク>)","宮城県","仙台市青葉区","土樋(1丁目「11を除く」)",0,0,1,0,0,0`,
},
{
`04101,"980 ","9800065","ミヤギケン","センダイシアオバク","ツチトイ","宮城県","仙台市青葉区","土樋",0,0,1,0,0,0`,
},
},
{
{
`01224,"066 ","0660005","ホッカイドウ","チトセシ","キョウワ(88-2、271-10、343-2、404-1、427-","北海道","千歳市","協和(88-2、271-10、343-2、404-1、427-",1,0,0,0,0,0`,
`01224,"066 ","0660005","ホッカイドウ","チトセシ","3、431-12、443-6、608-2、641-8、814、842-","北海道","千歳市","3、431-12、443-6、608-2、641-8、814、842-",1,0,0,0,0,0`,
`01224,"066 ","0660005","ホッカイドウ","チトセシ","5、1137-3、1392、1657、1752バンチ)","北海道","千歳市","5、1137-3、1392、1657、1752番地)",1,0,0,0,0,0`,
`01224,"06911","0691182","ホッカイドウ","チトセシ","キョウワ(ソノタ)","北海道","千歳市","協和(その他)",1,0,0,0,0,0`,
},
{
`01224,"066 ","0660005","ホッカイドウ","チトセシ","キョウワ","北海道","千歳市","協和",1,0,0,0,0,0`,
`01224,"06911","0691182","ホッカイドウ","チトセシ","キョウワ","北海道","千歳市","協和",1,0,0,0,0,0`,
},
},
{
{
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラ(アオバチョウ、オオウラ、カイシャマチ、カスミガオカ、ゴトウジニシダンチ、ゴトウジヒガシダンチ、ノゾミガオカ、","福岡県","田川市","奈良(青葉町、大浦、会社町、霞ケ丘、後藤寺西団地、後藤寺東団地、希望ケ丘、",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","マツノキ、ミツイゴトウジ、ミドリマチ、ツキミガオカ)","福岡県","田川市","松の木、三井後藤寺、緑町、月見ケ丘)",0,0,0,0,0,0`,
`40206,"826 ","8260024","フクオカケン","タガワシ","ニシホンマチ","福岡県","田川市","西本町",0,0,0,0,0,0`,
},
{
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラアオバチョウ","福岡県","田川市","奈良青葉町",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラオオウラ","福岡県","田川市","奈良大浦",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラカイシャマチ","福岡県","田川市","奈良会社町",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラカスミガオカ","福岡県","田川市","奈良霞ケ丘",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラゴトウジニシダンチ","福岡県","田川市","奈良後藤寺西団地",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラゴトウジヒガシダンチ","福岡県","田川市","奈良後藤寺東団地",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラノゾミガオカ","福岡県","田川市","奈良希望ケ丘",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラマツノキ","福岡県","田川市","奈良松の木",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラミツイゴトウジ","福岡県","田川市","奈良三井後藤寺",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラミドリマチ","福岡県","田川市","奈良緑町",0,0,0,0,0,0`,
`40206,"826 ","8260043","フクオカケン","タガワシ","ナラツキミガオカ","福岡県","田川市","奈良月見ケ丘",0,0,0,0,0,0`,
`40206,"826 ","8260024","フクオカケン","タガワシ","ニシホンマチ","福岡県","田川市","西本町",0,0,0,0,0,0`,
},
},
}
type testT struct {
name string
pushes []*JapanZipCode
pops []*JapanZipCode
}
tests := []*testT{}
for _, ba := range beforeAfter {
tt := &testT{"", []*JapanZipCode{}, []*JapanZipCode{}}
for _, before := range ba[0] {
jzc, _ := parseCSV(before, false)
tt.pushes = append(tt.pushes, jzc)
}
for _, after := range ba[1] {
jzc, _ := parseCSV(after, false)
tt.pops = append(tt.pops, jzc)
}
tests = append(tests, tt)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
normer := newNormalizer()
for _, push := range tt.pushes {
normer.push(push)
}
for _, pop := range tt.pops {
if got := normer.pop(); !reflect.DeepEqual(got, pop) {
t.Errorf("normalizer.pop() = %v, want %v", got, pop)
}
}
})
}
}
func Test_zenkaku2Int(t *testing.T) {
type args struct {
t string
}
tests := []struct {
name string
args args
want int
}{
{"", args{"1234567890"}, 1234567890},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := zenkaku2Int(tt.args.t); got != tt.want {
t.Errorf("zenkaku2Int() = %v, want %v", got, tt.want)
}
})
}
}
func Test_int2Zenkaku(t *testing.T) {
type args struct {
i int
}
tests := []struct {
name string
args args
want string
}{
{"", args{1234567890}, "1234567890"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := int2Zenkaku(tt.args.i); got != tt.want {
t.Errorf("int2Zenkaku() = %v, want %v", got, tt.want)
}
})
}
}