tests/testthat/test-Best.R

library(functools)
context("Best()")

test_that("Produces the correct output.", {
  expect_equal(Best(1:10, function(x, y) return(x > y)), 10)
  expect_equal(Best(1:10, function(x, y) return(x < y)), 1)
  expect_equal(Best(letters, function(x, y) return(x[1] == "l")), "l")
})

test_that("Produces the correct output type.", {
  expect_is(Best(1:10, function(x, y) return(x > y)), "integer")
  expect_is(Best(1:10, function(x, y) return(x < y)), "integer")
  expect_is(Best(letters, function(x, y) return(x[1] == "l")), "character")
})

test_that("Produces the correct errors.", {
  expect_error(Best(1:10, function(x, y, z) return(y < z)))
})

Try the functools package in your browser

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

functools documentation built on May 2, 2019, 5:39 a.m.