Skip to content
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
1 change: 0 additions & 1 deletion R/central-tendency.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO:
# - Add tests
# - Add description

#' Geometric Mean (GM)
Expand Down
5 changes: 4 additions & 1 deletion R/variability.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TODO:
# - Add tests
# - Add description

#' Coefficient of Variation (Cv)
Expand Down Expand Up @@ -52,13 +51,17 @@ cv.data.frame <- function(
)
}

# TODO:
# Rewrite in C++

#' @rdname cv
#' @export
cv_vec <- function(
truth,
na_rm = TRUE,
...
) {
# ugly, might not need
yardstick::check_numeric_metric(truth, truth, case_weights = NULL)

if (na_rm) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(checkmate)
library(tidyhydro)

test_check("tidyhydro")
9 changes: 9 additions & 0 deletions tests/testthat/test-kge.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ test_that("Internal function works as expected", {
kge_cpp(ex_dat$obs, ex_dat$pred, na_rm = TRUE, version = "2012")
)
})

test_that("Negative values are not allowed in kgelog", {
x <- rnorm(100)
y <- rnorm(100)

expect_error(kgelog_vec(x, y))
expect_error(kgelog_hi_vec(x, y))
expect_error(kgelog_low_vec(x, y))
})
5 changes: 5 additions & 0 deletions tests/testthat/test-measures.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test_that("Negative values are not allowed in GM", {
x <- rnorm(100)

expect_error(gm_vec(x))
})
Loading
Loading