@@ -5,78 +5,147 @@ test_that('geohash decoder works', {
55 neum = ' srss0'
66
77 # test defaults on scalar input
8- expect_equal(gh_decode(borobudur ),
9- list (latitude = - 7.60528564453125 ,
10- longitude = 110.1983642578125 ))
11- expect_equal(gh_decode(c(borobudur , akarenga )),
12- list (latitude = c(- 7.60528564453125 , 41.7672729492188 ),
13- longitude = c(110.198364257812 , 140.718383789062 )))
8+ expect_identical(
9+ gh_decode(borobudur ),
10+ list (latitude = - 7.60528564453125 , longitude = 110.1983642578125 ),
11+ tolerance = 1e-8
12+ )
13+ expect_identical(
14+ gh_decode(c(borobudur , akarenga )),
15+ list (latitude = c(- 7.60528564453125 , 41.7672729492188 ), longitude = c(110.198364257812 , 140.718383789062 )),
16+ tolerance = 1e-8
17+ )
1418 # # precision can vary
15- expect_equal(gh_decode(c(borobudur , neum )),
16- list (latitude = c(- 7.60528564453125 , 42.91259765625 ),
17- longitude = c(110.198364257812 , 17.60009765625 )))
19+ expect_identical(
20+ gh_decode(c(borobudur , neum )),
21+ list (latitude = c(- 7.60528564453125 , 42.91259765625 ), longitude = c(110.198364257812 , 17.60009765625 )),
22+ tolerance = 1e-8
23+ )
1824
1925 # input is factor, #17
2026 x = gl(4L , 20L , labels = c(borobudur , akarenga , kalakuta , neum ))
21- expect_equal (gh_decode(x ), gh_decode(as.character(x )))
27+ expect_identical (gh_decode(x ), gh_decode(as.character(x )))
2228
2329 # option: include_delta
24- expect_equal(gh_decode(borobudur , include_delta = TRUE ),
25- list (latitude = - 7.60528564453125 ,
26- longitude = 110.198364257812 ,
27- delta_latitude = 0.00274658203125 ,
28- delta_longitude = 0.0054931640625 ))
30+ expect_identical(
31+ gh_decode(borobudur , include_delta = TRUE ),
32+ list (
33+ latitude = - 7.60528564453125 ,
34+ longitude = 110.198364257812 ,
35+ delta_latitude = 0.00274658203125 ,
36+ delta_longitude = 0.0054931640625
37+ ),
38+ tolerance = 1e-8
39+ )
2940 # # different precision, different delta
30- expect_equal(gh_decode(c(borobudur , neum ), include_delta = TRUE ),
31- list (latitude = c(- 7.60528564453125 , 42.91259765625 ),
32- longitude = c(110.198364257812 , 17.60009765625 ),
33- delta_latitude = c(0.00274658203125 , 0.02197265625 ),
34- delta_longitude = c(0.0054931640625 , 0.02197265625 )))
41+ expect_identical(
42+ gh_decode(c(borobudur , neum ), include_delta = TRUE ),
43+ list (
44+ latitude = c(- 7.60528564453125 , 42.91259765625 ),
45+ longitude = c(110.198364257812 , 17.60009765625 ),
46+ delta_latitude = c(0.00274658203125 , 0.02197265625 ),
47+ delta_longitude = c(0.0054931640625 , 0.02197265625 )
48+ ),
49+ tolerance = 1e-8
50+ )
3551
3652 # option: coord_loc
37- expect_equal(gh_decode(borobudur , coord_loc = ' se' ),
38- list (latitude = - 7.6080322265625 , longitude = 110.203857421875 ))
39- expect_equal(gh_decode(borobudur , coord_loc = ' southeast' ),
40- list (latitude = - 7.6080322265625 , longitude = 110.203857421875 ))
41- expect_equal(gh_decode(borobudur , coord_loc = ' s' ),
42- list (latitude = - 7.6080322265625 , longitude = 110.198364257812 ))
43- expect_equal(gh_decode(borobudur , coord_loc = ' south' ),
44- list (latitude = - 7.6080322265625 , longitude = 110.198364257812 ))
45- expect_equal(gh_decode(borobudur , coord_loc = ' sw' ),
46- list (latitude = - 7.6080322265625 , longitude = 110.19287109375 ))
47- expect_equal(gh_decode(borobudur , coord_loc = ' southwest' ),
48- list (latitude = - 7.6080322265625 , longitude = 110.19287109375 ))
49- expect_equal(gh_decode(borobudur , coord_loc = ' w' ),
50- list (latitude = - 7.60528564453125 , longitude = 110.19287109375 ))
51- expect_equal(gh_decode(borobudur , coord_loc = ' west' ),
52- list (latitude = - 7.60528564453125 , longitude = 110.19287109375 ))
53- expect_equal(gh_decode(borobudur , coord_loc = ' nw' ),
54- list (latitude = - 7.6025390625 , longitude = 110.19287109375 ))
55- expect_equal(gh_decode(borobudur , coord_loc = ' northwest' ),
56- list (latitude = - 7.6025390625 , longitude = 110.19287109375 ))
57- expect_equal(gh_decode(borobudur , coord_loc = ' n' ),
58- list (latitude = - 7.6025390625 , longitude = 110.198364257812 ))
59- expect_equal(gh_decode(borobudur , coord_loc = ' north' ),
60- list (latitude = - 7.6025390625 , longitude = 110.198364257812 ))
61- expect_equal(gh_decode(borobudur , coord_loc = ' ne' ),
62- list (latitude = - 7.6025390625 , longitude = 110.203857421875 ))
63- expect_equal(gh_decode(borobudur , coord_loc = ' northeast' ),
64- list (latitude = - 7.6025390625 , longitude = 110.203857421875 ))
65- expect_equal(gh_decode(borobudur , coord_loc = ' e' ),
66- list (latitude = - 7.60528564453125 , longitude = 110.203857421875 ))
67- expect_equal(gh_decode(borobudur , coord_loc = ' east' ),
68- list (latitude = - 7.60528564453125 , longitude = 110.203857421875 ))
69-
53+ expect_identical(
54+ gh_decode(borobudur , coord_loc = ' se' ),
55+ list (latitude = - 7.6080322265625 , longitude = 110.203857421875 ),
56+ tolerance = 1e-8
57+ )
58+ expect_identical(
59+ gh_decode(borobudur , coord_loc = ' southeast' ),
60+ list (latitude = - 7.6080322265625 , longitude = 110.203857421875 ),
61+ tolerance = 1e-8
62+ )
63+ expect_identical(
64+ gh_decode(borobudur , coord_loc = ' s' ),
65+ list (latitude = - 7.6080322265625 , longitude = 110.198364257812 ),
66+ tolerance = 1e-8
67+ )
68+ expect_identical(
69+ gh_decode(borobudur , coord_loc = ' south' ),
70+ list (latitude = - 7.6080322265625 , longitude = 110.198364257812 ),
71+ tolerance = 1e-8
72+ )
73+ expect_identical(
74+ gh_decode(borobudur , coord_loc = ' sw' ),
75+ list (latitude = - 7.6080322265625 , longitude = 110.19287109375 ),
76+ tolerance = 1e-8
77+ )
78+ expect_identical(
79+ gh_decode(borobudur , coord_loc = ' southwest' ),
80+ list (latitude = - 7.6080322265625 , longitude = 110.19287109375 ),
81+ tolerance = 1e-8
82+ )
83+ expect_identical(
84+ gh_decode(borobudur , coord_loc = ' w' ),
85+ list (latitude = - 7.60528564453125 , longitude = 110.19287109375 ),
86+ tolerance = 1e-8
87+ )
88+ expect_identical(
89+ gh_decode(borobudur , coord_loc = ' west' ),
90+ list (latitude = - 7.60528564453125 , longitude = 110.19287109375 ),
91+ tolerance = 1e-8
92+ )
93+ expect_identical(
94+ gh_decode(borobudur , coord_loc = ' nw' ),
95+ list (latitude = - 7.6025390625 , longitude = 110.19287109375 ),
96+ tolerance = 1e-8
97+ )
98+ expect_identical(
99+ gh_decode(borobudur , coord_loc = ' northwest' ),
100+ list (latitude = - 7.6025390625 , longitude = 110.19287109375 ),
101+ tolerance = 1e-8
102+ )
103+ expect_identical(
104+ gh_decode(borobudur , coord_loc = ' n' ),
105+ list (latitude = - 7.6025390625 , longitude = 110.198364257812 ),
106+ tolerance = 1e-8
107+ )
108+ expect_identical(
109+ gh_decode(borobudur , coord_loc = ' north' ),
110+ list (latitude = - 7.6025390625 , longitude = 110.198364257812 ),
111+ tolerance = 1e-8
112+ )
113+ expect_identical(
114+ gh_decode(borobudur , coord_loc = ' ne' ),
115+ list (latitude = - 7.6025390625 , longitude = 110.203857421875 ),
116+ tolerance = 1e-8
117+ )
118+ expect_identical(
119+ gh_decode(borobudur , coord_loc = ' northeast' ),
120+ list (latitude = - 7.6025390625 , longitude = 110.203857421875 ),
121+ tolerance = 1e-8
122+ )
123+ expect_identical(
124+ gh_decode(borobudur , coord_loc = ' e' ),
125+ list (latitude = - 7.60528564453125 , longitude = 110.203857421875 ),
126+ tolerance = 1e-8
127+ )
128+ expect_identical(
129+ gh_decode(borobudur , coord_loc = ' east' ),
130+ list (latitude = - 7.60528564453125 , longitude = 110.203857421875 ),
131+ tolerance = 1e-8
132+ )
70133 # be sure adjacent geohashes interlock
71- expect_equal (lapply(c(' nw' , ' n' , ' ne' ),
134+ expect_identical (lapply(c(' nw' , ' n' , ' ne' ),
72135 function (l ) gh_decode(' m' , coord_loc = l )),
73136 lapply(c(' sw' , ' s' , ' se' ),
74137 function (l ) gh_decode(' t' , coord_loc = l )))
75138
76- expect_error(gh_decode(c(borobudur , neum ), coord_loc = c(' n' , ' s' )),
77- ' Please provide only one value' , fixed = TRUE )
78- expect_error(gh_decode(akarenga , coord_loc = ' yo' ),
79- error = ' Unrecognized coordinate location' )
139+ expect_error(
140+ gh_decode(c(borobudur , neum ), coord_loc = c(' n' , ' s' )),
141+ ' Please provide only one value' ,
142+ fixed = TRUE
143+ )
144+ expect_error(
145+ gh_decode(akarenga , coord_loc = ' yo' ),
146+ ' Unrecognized coordinate location' ,
147+ fixed = TRUE
148+ )
80149
81150 # invalid geohash characters:
82151 expect_error(gh_decode(' a' ), fixed = TRUE ,
@@ -85,26 +154,28 @@ test_that('geohash decoder works', {
85154 " Invalid geohash; check 'a' at index 2." )
86155
87156 # missing input
88- expect_equal (gh_decode(c(neum , NA_character_ )),
157+ expect_identical (gh_decode(c(neum , NA_character_ )),
89158 list (latitude = c(42.91259765625 , NA ),
90159 longitude = c(17.60009765625 , NA )))
91- expect_equal (gh_decode(c(neum , NA_character_ ), include_delta = TRUE ),
160+ expect_identical (gh_decode(c(neum , NA_character_ ), include_delta = TRUE ),
92161 list (latitude = c(42.91259765625 , NA ),
93162 longitude = c(17.60009765625 , NA ),
94163 delta_latitude = c(0.02197265625 , NA ),
95164 delta_longitude = c(0.02197265625 , NA )))
96165
97166 # stress testing
98167 # # empty input
99- expect_equal (gh_decode(character (0L )),
168+ expect_identical (gh_decode(character (0L )),
100169 list (latitude = numeric (0L ), longitude = numeric (0L )))
101170 # # !nzchar input
102- expect_equal (gh_decode(' ' ),
171+ expect_identical (gh_decode(' ' ),
103172 list (latitude = NA_real_ , longitude = NA_real_ ))
104173 # # long input [intr_length > 8 in geohash_decode_impl]
105- expect_equal(gh_decode(strrep(' 1' , 26L )),
106- list (latitude = - 84.1935483870968 ,
107- longitude = - 133.548387117729 ))
174+ expect_identical(
175+ gh_decode(strrep(' 1' , 26L )),
176+ list (latitude = - 84.1935483870968 , longitude = - 133.548387117729 ),
177+ tolerance = 1e-8
178+ )
108179
109180 # # non-ASCII input #19
110181 # # useBytes needed a bit strangely -- that the error returns with _any_
0 commit comments