-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy patharea_test.rb
More file actions
123 lines (92 loc) · 3.3 KB
/
area_test.rb
File metadata and controls
123 lines (92 loc) · 3.3 KB
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
require 'minitest/autorun'
require 'area'
class TestInteger < MiniTest::Unit::TestCase
def test_that_it_converts_area_code_to_region
assert_equal "New York", 646.to_region
end
def test_that_it_converts_zip_code_to_latlon
assert_equal "40.71209, -73.95427", 11211.to_latlon
end
def test_that_it_converts_zip_code_to_lat
assert_equal "40.71209", 11211.to_lat
end
def test_that_it_converts_zip_code_to_lon
assert_equal "-73.95427", 11211.to_lon
end
def test_that_it_converts_zip_code_int_to_gmt_offset
assert_equal "-5", 11211.to_gmt_offset
end
def test_that_it_handles_bad_area_codes
assert_raises(ArgumentError) { 1234.to_region }
assert_raises(ArgumentError) { 1234.to_latlon }
assert_raises(ArgumentError) { 1234.to_lat }
assert_raises(ArgumentError) { 1234.to_lon }
assert_raises(ArgumentError) { 1234.to_gmt_offset }
end
end
class TestString < MiniTest::Unit::TestCase
def test_that_it_converts_area_code_to_region
assert_equal "New York", "646".to_region
end
def test_that_it_converts_zip_code_to_region
assert_equal "Brooklyn, NY", "11211".to_region
end
def test_that_it_supports_options
assert_equal "Brooklyn", "11211".to_region(:city => true)
assert_equal "New York", "11211".to_region(:state => true)
end
def test_that_it_converts_to_area_code
assert_equal ["907"], "Alaska".to_area
assert_equal ["203", "860"], "Connecticut".to_area
end
def test_that_it_converts_to_zip_code
assert_equal ["10706"], "hastings on hudson".to_zip
assert_equal ["11101", "11109", "11120"], "long Island city".to_zip
end
def test_that_it_converts_city_state_to_zip_code
assert_equal ["11101", "11109", "11120"], "long Island city, ny".to_zip
end
def test_that_it_converts_to_offset
assert_equal "-5", "New York".to_gmt_offset
end
def test_that_it_handles_incorrect_zips
assert_equal [], "9888".to_zip
assert_raises(ArgumentError) { "9888".to_region }
assert_raises(ArgumentError) { "9888".to_area }
assert_raises(ArgumentError) { "9888".to_gmt_offset }
end
def test_that_it_converts_zip_code_to_latlon
assert_equal "40.71209, -73.95427", "11211".to_latlon
end
def test_that_it_converts_zip_code_to_lat
assert_equal "40.71209", "11211".to_lat
end
def test_that_it_converts_zip_code_to_lon
assert_equal "-73.95427", "11211".to_lon
end
def test_that_it_converts_zip_code_to_gmt_offset
assert_equal "-5", "11211".to_gmt_offset
end
end
class TestArray < MiniTest::Unit::TestCase
def test_that_it_converts_latlon_to_zip_code
assert_equal "11211", [40.71209, -73.95427].to_zip
end
def test_that_it_converts_latlon_to_region
assert_equal "Brooklyn, NY", [40.71209, -73.95427].to_region
end
def test_that_it_converts_latlon_to_region_with_options
assert_equal "New York", [40.71209, -73.95427].to_region(:state => true)
end
def test_that_it_converts_latlon_to_gmt_offset
assert_equal "-5", [40.71209, -73.95427].to_gmt_offset
end
def test_that_it_handles_latlon_precision
assert_equal "11211", [40.71209123228157, -73.95488409019887].to_zip
end
def test_that_it_handles_incorrect_values
assert_nil [12.12345, -40.23423].to_zip
assert_nil [12.12345, -40.23423].to_region
assert_nil [12.12345, -40.23423].to_gmt_offset
end
end