Skip to content

Commit

Permalink
added tests for .fit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Jan 30, 2024
1 parent f348ea0 commit ade7699
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -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"
)
})

0 comments on commit ade7699

Please sign in to comment.