Skip to content

Commit

Permalink
Merge pull request #50 from DOI-USGS/49
Browse files Browse the repository at this point in the history
add error handling for missing start value fixes #49
  • Loading branch information
dblodgett-usgs authored Oct 19, 2024
2 parents 03092c4 + 43c7cc0 commit 407e947
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions R/navigation_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ navigate_hydro_network <- function(x, start, mode, distance = NULL) {
stop("must choose mode input from: 'UM', 'DM', 'UT', 'DD'")
}

if(is.na(start)) stop("Must provide a value for start.")

required_atts <- required_atts_navigate(mode, distance)

if(missing(x)) {
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test_navigate_hydro_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
x <- readRDS(list.files(pattern = "network.rds", recursive = TRUE, full.names = TRUE))

test_that("get_DM works normal", {
expect_error(navigate_hydro_network(dplyr::select(x, -COMID), mode = "DM"),
expect_error(navigate_hydro_network(dplyr::select(x, -COMID), 1234, mode = "DM"),
"DM requires.*")

expect_error(navigate_hydro_network(mode = "BK"),
"must choose mode input from: 'UM', 'DM', 'UT', 'DD'")

expect_error(navigate_hydro_network(mode = "DD"), "DD requires.*")
expect_error(navigate_hydro_network(dplyr::select(x, -COMID),
1234, mode = "DD"), "DD requires.*")

result <- navigate_hydro_network(x, 11689050, "DM")
expect_equal(length(result), 26)
Expand Down Expand Up @@ -155,5 +156,7 @@ test_that("get_DM works if missing the outlet", {
x_borkd <- dplyr::filter(x, TerminalFl == 0)
result <- navigate_hydro_network(x_borkd, 11688810, "DM")
expect_equal(length(result), 34)

expect_error(navigate_hydro_network(x_borked, NA, "DM"), "Must provide a value for start.")
})

0 comments on commit 407e947

Please sign in to comment.