-
Notifications
You must be signed in to change notification settings - Fork 3
/
jpostcode_test.go
81 lines (76 loc) · 1.75 KB
/
jpostcode_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
package jpostcode
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_Find(t *testing.T) {
tests := map[string]struct {
postCode string
want *Address
wantErr error
}{
"OK": {
postCode: "1638001",
want: &Address{
PostCode: "1638001",
Prefecture: "東京都",
PrefectureKana: "トウキョウト",
PrefectureCode: 13,
City: "新宿区",
CityKana: "シンジュクク",
Town: "西新宿",
TownKana: "ニシシンジュク",
Street: "2丁目8−1",
OfficeName: "東京都庁",
OfficeNameKana: "トウキヨウトチヨウ",
},
},
"NG with invalid too long postCode": {
postCode: "12345678", // too long
want: nil,
wantErr: ErrInvalidArgument,
},
"NG with invalid too short postCode": {
postCode: "123456", // too short
want: nil,
wantErr: ErrInvalidArgument,
},
"NG with not found by firstPostCode": {
postCode: "0008001", // not found by first 3 digits
want: nil,
wantErr: ErrNotFound,
},
"NG with not found by lastPostCode": {
postCode: "1630000", // not found by last 4 digits
want: nil,
wantErr: ErrNotFound,
},
}
for n, tt := range tests {
t.Run(n, func(t *testing.T) {
got, err := Find(tt.postCode)
if tt.wantErr != nil {
if tt.wantErr != err {
t.Fatalf("want err: %v, got: %v", tt.wantErr, err)
}
return
}
if d := cmp.Diff(tt.want, got); d != "" {
t.Fatal(d)
}
})
}
}
func Benchmark_MapAdapter_Search(b *testing.B) {
adapter, err := newMapAdapter()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := adapter.SearchAddressesFromPostCode("1638001")
if err != nil {
b.Error(err)
}
}
}