inst/tinytest/test_approx.R

## fastapprox
library("tinytest")

test_fastapprox <- function() {
  set.seed(1)
  x <- sort(rnorm(1e5))
  y <- rnorm(1e3)
  val <- x[fast.approx(x, y)]
  val2 <- sapply(y, function(y) x[which.min(abs(x - y))])
  expect_identical(val, val2)
  ##rbenchmark::benchmark(fast.approx(x,y,type="left"),replications=1000)
  ##rbenchmark::benchmark(prodlim::sindex(x,y),replications=1000)
  val <- fast.approx(x, y, type="left") # Number of observations in x less than y
  val3 <- prodlim::sindex(x, y)
  expect_identical(val, val3)
}
test_fastapprox()

Try the mets package in your browser

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

mets documentation built on June 8, 2025, 1:24 p.m.