|
| 1 | +package jpareacode |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestCityByName(t *testing.T) { |
| 9 | + e := &City{PrefCode: 13, Name: "千代田区", Code: 13101} |
| 10 | + if c := CityByName(13, "千代田区"); !reflect.DeepEqual(c, e) { |
| 11 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 12 | + } |
| 13 | + e = nil |
| 14 | + if c := CityByName(12, "千代田区"); !reflect.DeepEqual(c, e) { |
| 15 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +func TestCitiesByName(t *testing.T) { |
| 20 | + e := []City{{PrefCode: 13, Name: "千代田区", Code: 13101}} |
| 21 | + if c := CitiesByName("千代田区"); !reflect.DeepEqual(c, e) { |
| 22 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 23 | + } |
| 24 | + e = nil |
| 25 | + if c := CitiesByName("千代田"); !reflect.DeepEqual(c, e) { |
| 26 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestCityByCode(t *testing.T) { |
| 31 | + e := &City{PrefCode: 13, Name: "千代田区", Code: 13101} |
| 32 | + if c := CityByCode(13101); !reflect.DeepEqual(c, e) { |
| 33 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 34 | + } |
| 35 | + e = nil |
| 36 | + if c := CityByCode(1310); !reflect.DeepEqual(c, e) { |
| 37 | + t.Errorf("expected: %#v, actual: %#v", e, c) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestFormatCityCode(t *testing.T) { |
| 42 | + if c := FormatCityCode(13101); c != "13101" { |
| 43 | + t.Errorf("expected: %s, actual: %s", "13101", c) |
| 44 | + } |
| 45 | + if c := FormatCityCode(0); c != "" { |
| 46 | + t.Errorf("expected: %s, actual: %s", "", c) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestParseCityCode(t *testing.T) { |
| 51 | + if c := ParseCityCode("13101"); c != 13101 { |
| 52 | + t.Errorf("expected: %d, actual: %d", 13101, c) |
| 53 | + } |
| 54 | + if c := ParseCityCode(""); c != 0 { |
| 55 | + t.Errorf("expected: %d, actual: %d", 0, c) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestValidateCityCode(t *testing.T) { |
| 60 | + if !ValidateCityCode(13101) { |
| 61 | + t.Error("expected: true, actual: false") |
| 62 | + } |
| 63 | + if ValidateCityCode(0) { |
| 64 | + t.Error("expected: false, actual: true") |
| 65 | + } |
| 66 | + if ValidateCityCode(50000) { |
| 67 | + t.Error("expected: false, actual: true") |
| 68 | + } |
| 69 | +} |
0 commit comments