tests/testthat/test_binbyvol.R

test_that("works as expected", {
  
  # Errors.
  expect_error( { iris$bin <- binbyvol( iris, 'Sepal.Widt', 'Sepal.Length', 5 ) }, 'not found' )
  expect_error( { iris$bin <- binbyvol( iris, 'Sepal.Width', 'Sepal.Lengt', 5 ) }, 'not found' )
  expect_error( { iris$bin <- binbyvol( iris, 'Species', 'Sepal.Length', 5 ) }, 'column must be numeric' )
  expect_error( { iris$bin <- binbyvol( iris, 'Sepal.Width', 'Sepal.Length', 'hello' ) }, 'argument must be a whole number' )
  
  # Other tests.
  iris$bin <- binbyvol( iris, 'Sepal.Width', 'Sepal.Length', 5 ) # runs without error.
  expect_equal( length( unique( iris$bin ) ), 5 ) # number of buckets (unique values) should be the same.
  
})
oliver-wyman-actuarial/easyR documentation built on Jan. 27, 2024, 4:35 a.m.