Debian Codegraph @

tests/testthat/test-list-optim.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 test_that("optim tidiers works", {
7 func <- function(x) {
8 (x[1] - 2)^2 + (x[2] - 3)^2 + (x[3] - 8)^2
9 }
10
11 o <- optim(c(1, 1, 1), func)
12
13 check_arguments(tidy_optim)
14 check_arguments(glance_optim)
15
16 td <- tidy(o)
17 check_tidy_output(td)
18 check_dims(td, 3, 2)
19
20 gl <- glance(o)
21 check_glance_outputs(gl)
22 })
23
24 test_that("optim std.error inclusion works", {
25 func <- function(x) {
26 (x[1] - 2)^2 + (x[2] - 3)^2 + (x[3] - 8)^2
27 }
28
29 o <- optim(c(1, 1, 1), func, hessian = TRUE)
30
31 check_arguments(tidy_optim)
32 check_arguments(glance_optim)
33
34 td <- tidy(o)
35 check_tidy_output(td)
36 check_dims(td, 3, 3)
37 expect_true("std.error" %in% names(td))
38 })