tests/testthat/test_inputchecks_predict_spending.R

fct.testthat.inputchecks.clvfittedspending.predict.newdata.has.no.spending <- function(fitted.spending){
  test_that("Fails if newdata has no spending data", {
    clv.newdata.nospending <- fct.helper.create.clvdata.cdnow(name.price=NULL)
    expect_error(predict(fitted.spending, clv.newdata.nospending),regexp = "spending")
  })
}


fct.testthat.inputchecks.clvfittedspending.predict.ellipsis <- function(fitted.spending){

  test_that("Stop if unnecessary inputs given in ellipsis", {
    expect_error(predict(fitted.spending, abc = 123), "further parameters")
    expect_error(predict(fitted.spending, use.cor = TRUE), "further parameters")
    expect_error(predict(fitted.spending, prediction.end = 6), "further parameters")
  })

}


fct.testthat.inputchecks.clvfittedspending.predict <- function(){
  clv.data.apparel.static.cov <- fct.helper.create.clvdata.apparel.staticcov()
  expect_silent(fitted.spending <- gg(clv.data.apparel.static.cov, verbose = FALSE))

  # General
  fct.testthat.inputchecks.clvfitted.na.in.prediction.params.model(s3method = predict, clv.fitted = fitted.spending, l.s3method.args=list())

  # Newdata
  fct.testthat.inputchecks.clvfitted.newdata.not.clvdata(s3method=predict, l.std.args=list(fitted.spending))
  fct.testthat.inputchecks.clvfittedspending.predict.newdata.has.no.spending(fitted.spending = fitted.spending)


  l.std.args <- list(object=fitted.spending)
  .fct.helper.inputchecks.single.logical(fct = predict, l.std.args = l.std.args,
                                         name.param = "verbose", null.allowed=FALSE)

  fct.testthat.inputchecks.clvfittedspending.predict.ellipsis(fitted.spending = fitted.spending)
}


fct.testthat.inputchecks.clvfittedspending.predict()

Try the CLVTools package in your browser

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

CLVTools documentation built on April 4, 2025, 2:02 a.m.