tests/testthat/test-bisection_method.R

test_that("error for same sign", {
  x0 <- 1
  x1 <- 2
  f <- function(x) x
  expect_error(bisection_method(f, x0, x1))
})

test_that("error for wrong endpoints", {
  x0 <- 1
  x1 <- -1
  f <- function(x) x
  expect_error(bisection_method(f, x0, x1))
})

test_that("sample rootfinding", {
  expect_equal(bisection_method(sin, -pi, pi), 0)
})
steventhornton/univariate documentation built on June 5, 2020, 2:37 p.m.