@@ -11,6 +11,9 @@ test_that("clean_highway strips _link suffix and filters values", {
1111 )
1212 )
1313
14+ clean_net <- clean_highway(toy_net )
15+ expect_identical(clean_net [[" highway" ]], c(" primary" , " residential" , " trunk" ))
16+
1417 filtered_net = clean_highway(
1518 toy_net ,
1619 highway_filter = c(" primary" , " residential" )
@@ -23,26 +26,25 @@ test_that("clean_highway strips _link suffix and filters values", {
2326
2427test_that(" clean_oneway standardises values and reverses -1 geometries" , {
2528 toy_net = sf :: st_sf(
26- oneway = c(NA , " alternating" , " reversible" , " -1" , " no" ),
27- junction = c(" roundabout" , NA , NA , NA , NA ),
29+ oneway = c(NA , " alternating" , " reversible" , " -1" , " no" , NA ),
30+ junction = c(" roundabout" , NA , NA , NA , NA , NA ),
2831 geometry = sf :: st_sfc(
2932 sf :: st_linestring(rbind(c(0 , 0 ), c(1 , 0 ))),
3033 sf :: st_linestring(rbind(c(1 , 0 ), c(2 , 0 ))),
3134 sf :: st_linestring(rbind(c(2 , 0 ), c(3 , 0 ))),
3235 sf :: st_linestring(rbind(c(3 , 0 ), c(4 , 0 ))),
3336 sf :: st_linestring(rbind(c(4 , 0 ), c(5 , 0 ))),
37+ sf :: st_linestring(rbind(c(5 , 0 ), c(6 , 0 ))),
3438 crs = 4326
3539 )
3640 )
3741
3842 clean_net = clean_oneway(toy_net )
3943
40- expect_identical(clean_net $ oneway , c(" yes" , " no" , " no" , " yes" , " no" ))
41-
42- reversed_coords = sf :: st_coordinates(clean_net $ geometry [4 ])
44+ expect_identical(clean_net $ oneway , c(" yes" , " no" , " no" , " yes" , " no" , " no" ))
4345 expect_identical(
44- unname( reversed_coords [, c( " X " , " Y " )]) ,
45- matrix ( c(4 , 0 , 3 , 0 ), ncol = 2 , byrow = TRUE )
46+ sf :: st_geometry( clean_net )[[ 4 ]] ,
47+ sf :: st_linestring(rbind( c(4 , 0 ), c( 3 , 0 )) )
4648 )
4749})
4850
@@ -95,7 +97,7 @@ test_that("oe_get_network cleans the highway and oneway values of the sample net
9597 expect_true(all(cleannet $ oneway %in% c(" yes" , " no" )))
9698})
9799
98- test_that(" oe_get_sfnetwork returns an sfnetwork and validates directed " , {
100+ test_that(" oe_get_sfnetwork returns an sfnetwork" , {
99101 skip_if_not_installed(" sfnetworks" )
100102 withr :: local_envvar(
101103 .new = list (
@@ -107,73 +109,52 @@ test_that("oe_get_sfnetwork returns an sfnetwork and validates directed", {
107109
108110 expect_warning(
109111 {
110- sfnet = oe_get_sfnetwork(" ITS Leeds" , mode = " driving" , quiet = TRUE )
111- },
112- regexp = " subdivision assumes attributes are constant"
113- )
114-
115- expect_s3_class(sfnet , " sfnetwork" )
116-
117- expect_error(
118- oe_get_sfnetwork(
119- " ITS Leeds" ,
120- mode = " driving" ,
121- directed = " yes" ,
122- quiet = TRUE
123- ),
124- " is.logical\\ (directed\\ ) is not TRUE"
125- )
126- })
127-
128- test_that(" oe_get_sfnetwork warns when oneway is missing" , {
129- withr :: local_envvar(
130- .new = list (
131- " OSMEXT_DOWNLOAD_DIRECTORY" = tempdir(),
132- " TESTTHAT" = " true"
133- )
134- )
135- its_pbf = setup_pbf()
136-
137- expect_warning(
138- expect_warning(
139- sfnet <- oe_get_sfnetwork(
112+ sfnet = oe_get_sfnetwork(
140113 " ITS Leeds" ,
141- mode = " walking " ,
142- directed = TRUE ,
114+ mode = " driving " ,
115+ download_directory = tempdir() ,
143116 quiet = TRUE
144- ),
145- regexp = " subdivision assumes attributes are constant"
146- ),
147- regexp = " column is missing"
117+ )
118+ },
119+ regexp = " attributes are constant"
148120 )
149121
150122 expect_s3_class(sfnet , " sfnetwork" )
151123})
152124
153- test_that(" net_2_sfnet_undirected and prepare_directed return sfnetwork objects" , {
125+ test_that(" net_2_sfnet_undirected and prepare_directed return sfnetwork objects and handle arguments correctly " , {
154126 skip_if_not_installed(" sfnetworks" )
155127 toy_net = sf :: st_sf(
156128 highway = c(" residential" , " residential" ),
157129 oneway = c(" no" , " yes" ),
158- junction = c(NA , NA ),
159- z_order = c(1 , 2 ),
160130 geometry = sf :: st_sfc(
161131 sf :: st_linestring(rbind(c(0 , 0 ), c(1 , 0 ))),
162132 sf :: st_linestring(rbind(c(1 , 0 ), c(2 , 0 ))),
163133 crs = 4326
164134 )
165135 )
136+ sf :: st_agr(toy_net ) <- c(" highway" = " constant" , " oneway" = " constant" )
166137
167- expect_warning(
168- {
169- undirected_net = net_2_sfnet_undirected(toy_net )
170- },
171- regexp = " subdivision assumes attributes"
138+ undirected_net = net_2_sfnet_undirected(toy_net )
139+ expect_s3_class(undirected_net , " sfnetwork" )
140+
141+ undirected_net = net_2_sfnet_undirected(toy_net )
142+ expect_shape(undirected_net | > sf :: st_as_sf(" edges" ), nrow = 2 )
143+
144+ undirected_net = net_2_sfnet_undirected(toy_net , require_equal = FALSE )
145+ expect_shape(undirected_net | > sf :: st_as_sf(" edges" ), nrow = 1 )
146+ expect_equal(
147+ (undirected_net | > sf :: st_as_sf(" edges" ))[[" oneway" ]],
148+ " no,yes"
172149 )
173150
174- directed_net = prepare_directed(undirected_net )
151+ undirected_net = net_2_sfnet_undirected(toy_net , require_equal = " highway" )
152+ expect_shape(undirected_net | > sf :: st_as_sf(" edges" ), nrow = 1 )
175153
176- expect_s3_class(undirected_net , " sfnetwork" )
154+ undirected_net = net_2_sfnet_undirected(toy_net , require_equal = " oneway" )
155+ expect_shape(undirected_net | > sf :: st_as_sf(" edges" ), nrow = 2 )
156+
157+ directed_net = prepare_directed(undirected_net )
177158 expect_s3_class(directed_net , " sfnetwork" )
178159})
179160
@@ -217,39 +198,12 @@ test_that("oe_get_dodgrnetwork warns when oneway is missing", {
217198 graph <- oe_get_dodgrnetwork(
218199 " ITS Leeds" ,
219200 mode = " walking" ,
220- wt_profile = " foot"
201+ wt_profile = " foot" ,
202+ quiet = TRUE
221203 ),
222204 regexp = " column is missing"
223205 )
224206
225207 expect_s3_class(graph , " dodgr_streetnet" )
226208})
227209
228- test_that(" oe_get_sfnetwork validates and respects require_equal parameter" , {
229- skip_if_not_installed(" sfnetworks" )
230- withr :: local_envvar(
231- .new = list (
232- " OSMEXT_DOWNLOAD_DIRECTORY" = tempdir(),
233- " TESTTHAT" = " true"
234- )
235- )
236- its_pbf = setup_pbf()
237-
238- # Test parameter validation
239- expect_error(
240- oe_get_sfnetwork(
241- " ITS Leeds" ,
242- mode = " driving" ,
243- require_equal = 123 ,
244- quiet = TRUE
245- )
246- )
247- expect_error(
248- oe_get_sfnetwork(
249- " ITS Leeds" ,
250- mode = " driving" ,
251- require_equal = " invalid_attribute" ,
252- quiet = TRUE
253- )
254- )
255- })
0 commit comments