From 8ce17279c60e90b7656ebbb99c587549452f2de7 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 30 Jan 2024 13:02:01 +0000 Subject: [PATCH] added tests for .fit --- tests/testthat/test-utils.R | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/testthat/test-utils.R diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 0000000..45467de --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,32 @@ +test_that(".fit works as expected" ,{ + func <- function(x) { + (x - 3)^2 + 5 + } + expect_equal(.fit(func = func, fit_method = "optim", upper = 5), 3) +}) + +test_that(".fit fails as expected", { + expect_error( + .fit(func = "function", fit_method = "optim"), + regexp = "func must be a function" + ) + func <- function(x) { + (x - 3)^2 + 5 + } + expect_error( + .fit(func = func, fit_method = "other"), + regexp = "(arg)*(should be one of)*(optim)*(grid)" + ) + expect_error( + .fit(func = func, fit_method = "optim", a = 1, a = 2), + regexp = "(Arguments)*(must have unique names)" + ) + expect_error( + .fit(func = func, fit_method = "optim", mthod = "L-BFGS-B"), + regexp = "Arguments supplied in `...` not valid" + ) + expect_error( + .fit(func = func, fit_method = "grid", method = "L-BFGS-B"), + regexp = "Arguments supplied in `...` not valid" + ) +})