tests/testthat/test.objectiveFunctionEvaluationr.R

context("objectiveFunctionEvaluation")

test_that("random seed handling", {
  
  res1a <- spot(x = NULL,
                fun = function(x,seed){set.seed(seed);funSphere(x)+rnorm(nrow(x))},
                  lower= c(-2,-3),
                  upper = c(1,2),
                  control=list(funEvals=15,noise=TRUE,seedFun=1)
                  )
  res1b <- spot(x=NULL,
                fun=function(x,seed){
                  set.seed(seed)
                  funSphere(x)+rnorm(nrow(x))},
                lower=c(-2,-3),
                upper=c(1,2),
                control=list(funEvals=15,noise=TRUE,seedFun=1))

  res2 <- spot(x=NULL,
                 function(x,seed){set.seed(seed)
                   funSphere(x)+rnorm(nrow(x))},
                 lower=c(-2,-3),
                 upper=c(1,2),
                 control=list(funEvals=15,noise=TRUE,seedFun=2))
    expect_true(identical(res1a$ybest, res1b$ybest))
    expect_false(identical(res1a$ybest, res2$ybest))
})

Try the SPOT package in your browser

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

SPOT documentation built on June 26, 2022, 1:06 a.m.