-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #802 from epiforecasts/add-tests-score
- Loading branch information
Showing
11 changed files
with
302 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +0,0 @@ | ||
test_that("customise_metric works correctly", { | ||
# Create a customised metric function | ||
custom_metric <- customise_metric(mean, na.rm = TRUE) | ||
|
||
# Use the customised metric function | ||
values <- c(1, 2, NA, 4, 5) | ||
expect_equal(custom_metric(values), 3) | ||
|
||
# Test with a different metric function | ||
custom_metric <- customise_metric(sum, na.rm = TRUE) | ||
expect_equal(custom_metric(values), 12) | ||
|
||
# Test with no additional arguments | ||
custom_metric <- customise_metric(mean) | ||
expect_true(is.na(custom_metric(values))) | ||
|
||
# make sure that customise_metric fails immediately (instead of at runtime) | ||
# when object doesn't exist | ||
expect_error( | ||
custom_metric <- customise_metric(print, x = doesnotexist), | ||
"object 'doesnotexist' not found" | ||
) | ||
|
||
# make sure that customise_metric still works even if original object is | ||
# deleted, meaning that the object is stored as part of the function | ||
argument <- c("hi", "hello", "I'm here") | ||
custom_metric <- customise_metric(print, x = argument) | ||
expect_output(custom_metric(), "I'm here") | ||
|
||
argument <- NULL | ||
expect_output(custom_metric(), "I'm here") | ||
|
||
# make sure that all of this still works even if argument is called "dots" | ||
# which is used internally | ||
dots <- "test" | ||
expect_output( | ||
# dots argument should be ignored and output should stay the same | ||
expect_equal(custom_metric(dots = dots), c("hi", "hello", "I'm here")), | ||
"I'm here" | ||
) | ||
}) | ||
|
||
|
||
|
||
test_that("customise_metric handles errors correctly", { | ||
# Test with a non-function metric | ||
expect_error( | ||
customise_metric("not_a_function", na.rm = TRUE), | ||
"Must be a function, not 'character'" | ||
) | ||
}) | ||
|
||
test_that("customise_metric is exported", { | ||
expect_equal(customise_metric, customise_metric) | ||
}) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.