Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage #27

Merged
merged 8 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion R/delineate-corridor.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
sf::st_as_sfc() |>
sf::st_transform(crs)

if (buffer_dist != 0) aoi <- sf::st_buffer(aoi, buffer_dist) else aoi
if (buffer_dist != 0) {
if (sf::st_is_longlat(aoi)) {
warning("The area of interest is in longlat coordinates. ",
"Consider using a projected CRS when buffering the AoI.")
}
aoi <- sf::st_buffer(aoi, buffer_dist)
} else {
aoi
}
}

#' Split the area of interest (AoI) by a river.
Expand Down Expand Up @@ -48,7 +56,7 @@
#' Simplify a street network by removing multiple edges and loops.
#'
#' Simplify the graph, removing loops and double-edge connections following
#' [this approach](https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html#simplify-network).

Check warning on line 59 in R/delineate-corridor.R

View workflow job for this annotation

GitHub Actions / lint

file=R/delineate-corridor.R,line=59,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 114 characters.
#'
#' @param net A network object
#'
Expand All @@ -66,8 +74,8 @@

#' Clean a street network by subdividing edges and removing pseudo-nodes.
#'
#' Subdivide edges by [adding missing nodes](https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html#subdivide-edges),

Check warning on line 77 in R/delineate-corridor.R

View workflow job for this annotation

GitHub Actions / lint

file=R/delineate-corridor.R,line=77,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 139 characters.
#' remove [pseudo-nodes](https://luukvdmeer.github.io/sfnetworks/articles/sfn02_preprocess_clean.html#smooth-pseudo-nodes),

Check warning on line 78 in R/delineate-corridor.R

View workflow job for this annotation

GitHub Actions / lint

file=R/delineate-corridor.R,line=78,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 123 characters.
#' and keep only the main connected component of the network.
#'
#' @param net A network object
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/test-delineate-corridor.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
test_that("given bounding box coordinates and crs, a correct AoI is returned", {
bb <- bucharest$bb
crs <- 4326
aoi <- define_aoi(bb, crs, buffer_dist = 0)
coords <- sf::st_coordinates(aoi)

bb_expected <- cbind(matrix(coords[1:2, 1]), matrix(coords[2:3, 2])) |> t()
colnames(bb_expected) <- c("min", "max")
rownames(bb_expected) <- c("x", "y")

expect_equal(bb, bb_expected)
})

test_that("buffering an AoI with geographic crs gives a warning", {
bb <- bucharest$bb
crs <- 32634
aoi <- define_aoi(bb, crs, buffer_dist = 0)

expect_warning(define_aoi(bb, crs, buffer_dist = 1000), regexp = NA)
})

test_that("splitting an AoI by a river gives two areas of interest", {
bb <- bucharest$bb
crs <- 4326
aoi <- define_aoi(bb, crs, buffer_dist = 0)
river <- bucharest$river_centerline

aoi_split <- split_aoi(aoi, sf::st_transform(river, sf::st_crs(aoi)))

expect_equal(length(aoi_split), 2)
})

test_that("street network is correctly trimmed", {
expect_equal(2 * 2, 4)
})

test_that("street network is correctly simplified", {
expect_equal(2 * 2, 4)
})
Loading