Skip to content

Commit

Permalink
test(get_*): code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dimfalk committed Nov 30, 2024
1 parent c333cff commit 83b6662
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion R/get_measurements.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' get_measurements(gauge)
#' get_measurements(gauge, discharge = TRUE)
#'
#' gauges <- get_gauges() |> dplyr::filter(waterbody == "Hüller Bach")
#' gauges <- get_gauges() |> dplyr::filter(waterbody == "Hammbach")
#'
#' get_measurements(gauges)
get_measurements <- function(x = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' gauge <- get_gauges() |> dplyr::filter(id == "10103")
#' get_meta(gauge)
#'
#' gauges <- get_gauges() |> dplyr::filter(waterbody == "Hüller Bach")
#' gauges <- get_gauges() |> dplyr::filter(waterbody == "Hammbach")
#' get_meta(gauges)
get_meta <- function(x = NULL) {

Expand Down
2 changes: 1 addition & 1 deletion man/get_measurements.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_meta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions tests/testthat/test-get_measurements.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,41 @@ test_that("Output class is as expected.", {

x <- gauges_ref |> dplyr::filter(id == "10103")



meas_1 <- get_measurements(x)

expect_equal(class(meas_1), "list")

expect_s3_class(meas_1[[1]], c("xts", "zoo"))



meas_2 <- get_measurements(x, discharge = TRUE)

expect_equal(class(meas_2), "list")

expect_s3_class(meas_2[[1]], c("xts", "zoo"))



y <- gauges_ref |> dplyr::filter(waterbody == "Hammbach")

meas_3 <- get_measurements(y)

expect_equal(class(meas_3), "list")

expect_s3_class(meas_3[[1]], c("xts", "zoo"))

expect_s3_class(meas_3[[2]], c("xts", "zoo"))
})

test_that("Attributes are as expected.", {

x <- gauges_ref |> dplyr::filter(id == "10103")



meas_1 <- get_measurements(x)

expect_equal(attr(meas_1[[1]], "STAT_ID"), "10103")

expect_equal(attr(meas_1[[1]], "PARAMETER"), "waterlevel")



meas_2 <- get_measurements(x, discharge = TRUE)

expect_equal(attr(meas_2[[1]], "STAT_ID"), "10103")
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ test_that("Output class is as expected.", {
meta <- get_meta(x)

expect_s3_class(meta, c("tbl_df", "tbl", "data.frame"))

y <- gauges_ref |> dplyr::filter(waterbody == "Hammbach")

meta <- get_meta(y)

expect_s3_class(meta, c("tbl_df", "tbl", "data.frame"))
})

test_that("Dimensions are as expected.", {
Expand All @@ -14,6 +20,12 @@ test_that("Dimensions are as expected.", {
meta <- get_meta(x)

expect_equal(dim(meta), c(1, 9))

y <- gauges_ref |> dplyr::filter(waterbody == "Hammbach")

meta <- get_meta(y)

expect_equal(dim(meta), c(2, 9))
})

test_that("Column names are as expected.", {
Expand Down

0 comments on commit 83b6662

Please sign in to comment.