tests/testthat/test-calibrar-optimh.R

library(calibrar)
library(testthat)

tfn = function(x) sum(x^2) + 10

# optimh ------------------------------------------------------------------

message("\nTests for optimh() -------- \n")

algorithms = c("AHR-ES", "Nelder-Mead", "SANN", "hjn",  
               "CMA-ES", "genSA", "DE", "soma", "genoud", "PSO", 
               "hybridPSO", "mads", "hjk", "hjkb", "nmk", "nmkb", "bobyqa")

for(alg in algorithms) {
  
  message(alg, " - ", date())
  
  test_that(sprintf("algorithm test: '%s'.", alg), {
    expect_no_error(
      optimh(par=rep(0.5, 5), fn = tfn, lower=rep(-100, 5), upper=rep(100, 5), 
             method=alg))
  })
}

message("\nTests for ahres() -------- \n")

test_that("ahres", {
  expect_no_error(
    suppressMessages(ahres(par=rep(0.5, 5), fn = tfn,
                           lower=rep(-100, 5), upper=rep(100, 5)
    )))
})

Try the calibrar package in your browser

Any scripts or data that you put into this service are public.

calibrar documentation built on May 29, 2024, 7:46 a.m.