Skip to content

Commit

Permalink
Merge pull request #27 from CityRiverSpaces/11-tests-cf
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
cforgaci authored Nov 11, 2024
2 parents 098de73 + 8a8ece7 commit ec67d9d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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 @@ define_aoi <- function(bb, crs, buffer_dist = 0) {
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
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)
})

0 comments on commit ec67d9d

Please sign in to comment.