tests/testthat/test-rect.R

context("midpt")

f <- function(x) { x^2 }
expect_equal(midpt(f, 0, 1, m = 10), 1 / 3, 1e-2)
expect_equal(midpt(f, 0, 1, m = 100), 1 / 3, 1e-3)
expect_equal(midpt(f, 0, 1, m = 1000), 1 / 3, 1e-4)

f <- function(x) { 1 / x }
expect_false(isTRUE(all.equal(midpt(f, 1, 10, m = 1000), log(10))))
expect_equal(midpt(f, 1, 10, m = 100), log(10), 1e-3)
expect_equal(midpt(f, 1, 10, m = 1000), log(10), 1e-4)

f <- function(x) { sin(x)^2 + cos(x)^2 }
expect_equal(midpt(f, -pi, pi, m = 10), 2 * pi, 1e-2)
expect_equal(midpt(f, -pi, pi, m = 100), 2 * pi, 1e-3)
expect_equal(midpt(f, -pi, pi, m = 1000), 2 * pi, 1e-4)

Try the cmna package in your browser

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

cmna documentation built on July 14, 2021, 5:11 p.m.