@@ -9,20 +9,16 @@ test_that('geohash encoder works', {
99 expect_identical(gh_encode(y , x ), gh_encode(y , x - 360.0 ))
1010
1111 # all level-1 centroids to be sure my manual logic for precision = 1 works
12- expect_identical(gh_encode(c(- 67.5 , - 67.5 , - 22.5 , - 22.5 , - 67.5 , - 67.5 , - 22.5 ,
13- - 22.5 , 22.5 , 22.5 , 67.5 , 67.5 , 22.5 , 22.5 , 67.5 ,
14- 67.5 , - 67.5 , - 67.5 , - 22.5 , - 22.5 , - 67.5 , - 67.5 ,
15- - 22.5 , - 22.5 , 22.5 , 22.5 , 67.5 , 67.5 , 22.5 , 22.5 ,
16- 67.5 , 67.5 ),
17- c(- 157.5 , - 112.5 , - 157.5 , - 112.5 , - 67.5 , - 22.5 ,
18- - 67.5 , - 22.5 , - 157.5 , - 112.5 , - 157.5 , - 112.5 ,
19- - 67.5 , - 22.5 , - 67.5 , - 22.5 , 22.5 , 67.5 , 22.5 ,
20- 67.5 , 112.5 , 157.5 , 112.5 , 157.5 , 22.5 , 67.5 ,
21- 22.5 , 67.5 , 112.5 , 157.5 , 112.5 , 157.5 ),
22- precision = 1L ),
23- c(' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' b' , ' c' ,
24- ' d' , ' e' , ' f' , ' g' , ' h' , ' j' , ' k' , ' m' , ' n' , ' p' , ' q' , ' r' ,
25- ' s' , ' t' , ' u' , ' v' , ' w' , ' x' , ' y' , ' z' ))
12+ # nolint start: line_length_linter.
13+ expect_identical(
14+ gh_encode(
15+ c(- 067.5 , - 67.5 , - 22.5 , - 22.5 , - 67.5 , - 67.5 , - 22.5 , - 22.5 , 22.5 , 22.5 , 67.5 , 67.5 , 22.5 , 22.5 , 67.5 , 67.5 , - 67.5 , - 67.5 , - 22.5 , - 22.5 , - 67.5 , - 67.5 , - 22.5 , - 22.5 , 22.5 , 22.5 , 67.5 , 67.5 , 22.5 , 22.5 , 67.5 , 67.5 ),
16+ c(- 157.5 , - 112.5 , - 157.5 , - 112.5 , - 67.5 , - 22.5 , - 67.5 , - 22.5 , - 157.5 , - 112.5 , - 157.5 , - 112.5 , - 67.5 , - 22.5 , - 67.5 , - 22.5 , 22.5 , 67.5 , 22.5 , 67.5 , 112.5 , 157.5 , 112.5 , 157.5 , 22.5 , 67.5 , 22.5 , 67.5 , 112.5 , 157.5 , 112.5 , 157.5 ),
17+ precision = 1L
18+ ),
19+ c(' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' b' , ' c' , ' d' , ' e' , ' f' , ' g' , ' h' , ' j' , ' k' , ' m' , ' n' , ' p' , ' q' , ' r' , ' s' , ' t' , ' u' , ' v' , ' w' , ' x' , ' y' , ' z' )
20+ )
21+ # nolint end: line_length_linter.
2622
2723 # geohash cells are _left closed, right open_: [x1, x2) x [y1, y2), see:
2824 # http://geohash.org/s000
@@ -31,23 +27,31 @@ test_that('geohash encoder works', {
3127 # boundary cases
3228 # need to balloon eps so that adding .5 doesn't obliterate sig figs
3329 eps = 1000.0 * .Machine $ double.eps
34- expect_identical(gh_encode(c(eps , eps , - eps , - eps ,
35- 90.0 - eps , 90.0 - eps , eps - 90.0 , eps - 90.0 ),
36- c(eps , - eps , eps , - eps ,
37- eps - 180.0 , 180.0 - eps , eps - 180.0 , 180.0 - eps )),
38- c(' s00000' , ' ebpbpb' , ' kpbpbp' , ' 7zzzzz' ,
39- ' bpbpbp' , ' zzzzzz' , ' 000000' , ' pbpbpb' ))
30+ expect_identical(
31+ gh_encode(
32+ c(eps , eps , - eps , - eps , 90.0 - eps , 90.0 - eps , eps - 90.0 , eps - 90.0 ),
33+ c(eps , - eps , eps , - eps , eps - 180.0 , 180.0 - eps , eps - 180.0 , 180.0 - eps )
34+ ),
35+ c(' s00000' , ' ebpbpb' , ' kpbpbp' , ' 7zzzzz' , ' bpbpbp' , ' zzzzzz' , ' 000000' , ' pbpbpb' )
36+ )
4037
4138 # test precision argument
4239 expect_identical(gh_encode(y , x , 12L ), ' s0h09nrnzgqv' )
4340 # maximum precision
4441 n = 25L
45- expect_identical(gh_encode(y , x , n ),
46- substring(' s0h09nrnzgqv8je0f4jpd0000' , 1L , n ))
42+ expect_identical(
43+ gh_encode(y , x , n ),
44+ substring(' s0h09nrnzgqv8je0f4jpd0000' , 1L , n )
45+ )
4746 # truncation beyond there
48- expect_warning(out <- gh_encode(y , x , n + 5L ),
49- ' Precision is limited' , fixed = TRUE )
50- expect_identical(out , substring(' s0h09nrnzgqv8je0f4jpd0000' , 1L , n ))
47+ expect_warning(
48+ expect_identical(
49+ gh_encode(y , x , n + 5L ),
50+ substring(' s0h09nrnzgqv8je0f4jpd0000' , 1L , n )
51+ ),
52+ ' Precision is limited' ,
53+ fixed = TRUE
54+ )
5155
5256 # implicit integer truncation
5357 expect_identical(gh_encode(y , x , 1.04 ), ' s' )
@@ -58,25 +62,39 @@ test_that('geohash encoder works', {
5862 # invalid input
5963 expect_error(gh_encode(100.0 , x ), ' Invalid latitude at index 1' , fixed = TRUE )
6064 expect_error(gh_encode(- 91.0 , x ), ' Invalid latitude at index 1' , fixed = TRUE )
61- expect_error(gh_encode(c(y , 90.0 ), c(x , x )),
62- ' Invalid latitude at index 2' , fixed = TRUE )
63- expect_error(gh_encode(y , x , c(5L , 6L )),
64- ' More than one precision value' , fixed = TRUE )
65- expect_error(gh_encode(c(y , y ), x ),
66- ' Inputs must be the same size' , fixed = TRUE )
65+ expect_error(
66+ gh_encode(c(y , 90.0 ), c(x , x )),
67+ ' Invalid latitude at index 2' ,
68+ fixed = TRUE
69+ )
70+ expect_error(
71+ gh_encode(y , x , c(5L , 6L )),
72+ ' More than one precision value' ,
73+ fixed = TRUE
74+ )
75+ expect_error(
76+ gh_encode(c(y , y ), x ),
77+ ' Inputs must be the same size' ,
78+ fixed = TRUE
79+ )
6780
6881 # semi-valid auto-corrected input -- 180 --> -180 by wrapping
6982 expect_identical(gh_encode(y , 180.0 ), ' 80008n' )
7083 expect_identical(gh_encode(y , 293475908.0 ), ' db508w' )
7184
7285 # missing/infinite input
7386 expect_identical(gh_encode(c(y , NA ), c(x , NA )), c(' s0h09n' , NA_character_ ))
74- expect_identical(gh_encode(c(NaN , Inf , - Inf , 1 : 3 ), c(1 : 3 , NaN , Inf , - Inf )),
75- rep(NA_character_ , 6L ))
87+ expect_identical(
88+ gh_encode(c(NaN , Inf , - Inf , 1 : 3 ), c(1 : 3 , NaN , Inf , - Inf )),
89+ rep(NA_character_ , 6L )
90+ )
7691
7792 # different branch for precision=1 of the above errors
78- expect_error(gh_encode(100.0 , x , 1L ),
79- ' Invalid latitude at index 1' , fixed = TRUE )
93+ expect_error(
94+ gh_encode(100.0 , x , 1L ),
95+ ' Invalid latitude at index 1' ,
96+ fixed = TRUE
97+ )
8098 expect_identical(gh_encode(y , 180.0 , 1L ), ' 8' )
8199 expect_identical(gh_encode(NA , NA , 1L ), NA_character_ )
82100
0 commit comments