Skip to content

Commit

Permalink
add tests for eq_get_links
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Aug 18, 2024
1 parent e78842c commit c021cfe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
48 changes: 27 additions & 21 deletions R/eq_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,33 @@ eq_get_links <- function(.url = "https://earthquake.phivolcs.dost.gov.ph/",
httr::set_config()

## Retrieve and structure data ----
url_list <- lapply(
lapply(
X = urls,
FUN = eq_get_links_
)

url_list_names <- urls |>
(\(x)
{
paste(
stringr::str_extract(
string = x, pattern = paste(month.name, collapse = "|")
),
stringr::str_extract(
string = x, pattern = "[0-9]{4}"
)
)
}
)() |>
(\(x)ifelse(x == "NA NA", format(Sys.Date(), format = "%B %Y"), x))()

names(url_list) <- url_list_names

url_list
) |>
unlist()

# url_list_names <- urls |>
# (\(x)
# {
# paste(
# stringr::str_extract(
# string = x, pattern = paste(month.name, collapse = "|")
# ),
# stringr::str_extract(
# string = x, pattern = "[0-9]{4}"
# )
# )
# }
# )() |>
# (\(x)ifelse(x == "NA NA", format(Sys.Date(), format = "%B %Y"), x))()
#
# names(url_list) <- url_list_names
#
# url_list
}

#'
#' @rdname eq_get
#' @export
#'
17 changes: 4 additions & 13 deletions tests/testthat/test-eq_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,12 @@ test_that("tables are of the correct structure", {

tab_list <- eq_get_links()

test_that("get table function outputs are as expected", {
expect_type(tab_list, "list")
})

test_that("tables are of the correct structure", {
expect_vector(tab_list, size = 1)
test_that("get_links function outputs are as expected", {
expect_vector(tab_list, ptype = character(), size = nrow(eq_data()))
})

tab_list <- eq_get_links(.year = 2020)

test_that("get table function outputs are as expected", {
expect_type(tab_list, "list")
})
tab_list <- eq_get_links(.year = 2018)

test_that("tables are of the correct structure", {
expect_vector(tab_list, size = 12)
expect_named(tab_list, expected = paste(month.name, 2020))
expect_vector(tab_list, ptype = character())
})

0 comments on commit c021cfe

Please sign in to comment.