File: test_optimizeSubInts.R

package info (click to toggle)
r-cran-bbmisc 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,248 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (15 lines) | stat: -rw-r--r-- 394 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
context("optimizeSubInts")

test_that("optimizeSubInts", {

  f = function(x) sin(x) * x
  z = optimizeSubInts(f, interval = c(0, 50), nsub = 200L)
  fopt = f(pi * 3 / 2 + 14 * pi)
  expect_true(abs(fopt -  z$objective) < 1e-1)

  # test with nsub = 1, had a bug here
  f = function(x) sum(x^2)
  z = optimizeSubInts(f, interval = c(-10, 10), nsub = 1)
  expect_true(abs(z$minimum) < 1e-5)
})