-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcity_test.go
69 lines (62 loc) · 1.8 KB
/
city_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
package jpareacode
import (
"reflect"
"testing"
)
func TestCityByName(t *testing.T) {
e := &City{PrefCode: 27, CityName: "堺市", CityCode: 27140, WardName: "北区", WardCode: 27146}
if c := CityByName(27, "堺市", "北区"); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
e = nil
if c := CityByName(28, "堺市", "北区"); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
}
func TestCitiesByName(t *testing.T) {
e := []City{{PrefCode: 13, WardName: "千代田区", WardCode: 13101}}
if c := CitiesByName("千代田区"); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
e = nil
if c := CitiesByName("千代田"); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
}
func TestCityByCode(t *testing.T) {
e := &City{PrefCode: 13, WardName: "千代田区", WardCode: 13101}
if c := CityByCode(13101); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
e = nil
if c := CityByCode(1310); !reflect.DeepEqual(c, e) {
t.Errorf("expected: %#v, actual: %#v", e, c)
}
}
func TestFormatCityCode(t *testing.T) {
if c := FormatCityCode(13101); c != "13101" {
t.Errorf("expected: %s, actual: %s", "13101", c)
}
if c := FormatCityCode(0); c != "" {
t.Errorf("expected: %s, actual: %s", "", c)
}
}
func TestParseCityCode(t *testing.T) {
if c := ParseCityCode("13101"); c != 13101 {
t.Errorf("expected: %d, actual: %d", 13101, c)
}
if c := ParseCityCode(""); c != 0 {
t.Errorf("expected: %d, actual: %d", 0, c)
}
}
func TestValidateCityCode(t *testing.T) {
if !ValidateCityCode(13101) {
t.Error("expected: true, actual: false")
}
if ValidateCityCode(0) {
t.Error("expected: false, actual: true")
}
if ValidateCityCode(50000) {
t.Error("expected: false, actual: true")
}
}