test_that("Full function test", {
  testthat::skip_on_cran()
  local_edition(3)

  ##load Example dataset
  data("Example_Data", envir = environment())

  SW({

  ##break function
  expect_error(model_DoseRate(data = "test"), regexp = "'data' is not a 'data.frame'")
  expect_error(model_DoseRate(data = data.frame(x = 1)), regexp = "The column names of your input data.frame do not match the requirements.")
  expect_error(model_DoseRate(data = data.frame()), regexp = "'data' is empty!")
  expect_error(suppressWarnings(model_DoseRate(data = data.frame(x = NA))), regexp = "'data' is empty\\!")
  expect_error(
    suppressWarnings(model_DoseRate(data = Example_Data[23,], n.MC = 10)),
    regexp = "Modelling failed, please check your input data, they may not be meaningful!")

  expect_message(model_DoseRate(
    data = Example_Data[23:24, ],
    n.MC = 2,
    verbose = FALSE
  ), regexp = "[model_DoseRate()] Calculation for sample LV314 failed:", fixed = TRUE)

  expect_error(suppressWarnings(model_DoseRate(data = Example_Data[14,],
                             DR_conv_factors = "error",
                             n.MC = 2,
  )), regexp = "'error' does not correspond to an available dose rate conversion dataset.\n        Allowed are: Carb2007, Adamiec_Aitken_1998, Guerin_et_al_2011, Liritzis_et_al_2013, Cresswell_et_al_2018")

  ##run simple example
  set.seed(1234)
  t <- expect_type(suppressWarnings(model_DoseRate(data = Example_Data[14,],
    n.MC = 2
  )), type = "list")

  ## simple regression check
  expect_equal(sum(as.numeric(t[,-1])), expected = 862.032, tolerance = 0.1)

  ##run with different conversion factors
  expect_type(
    suppressWarnings(model_DoseRate(
      data = Example_Data[14, ],
      DR_conv_factors = "Adamiec_Aitken_1998",
      n.MC = 2,
      verbose = FALSE
    )),
    type = "list"
  )

  ##run extreme case warning
  temp <- Example_Data[14, ]
  temp$DE <- 550
  ##TODO the warning appears 16 times ... to much
  # expect_warning(
  #   model_DoseRate(
  #     data = temp,
  #     n.MC = 2,
  #     txtProgressBar = FALSE
  #   ),
  #   regexp = "\\[\\.calc_DoseRate\\(\\)\\] Extrem case detected: DE > max cumulative dose rate!"
  # )

  ##run two example
  expect_type(model_DoseRate(
    data = Example_Data[13:14, ],
    n.MC = 5,
    verbose = FALSE
  ),
  type = "list")

  ##run with n.MC == 1
  out <- expect_type(model_DoseRate(
    data = Example_Data[14, ],
    n.MC = 1,
    verbose = FALSE,
    plot = FALSE
  ),
  type = "list")

  ##run with parallel
  expect_message(model_DoseRate(
    data = Example_Data[14, ],
    n.MC = 5,
    plot = FALSE,
    verbose = TRUE,
    multicore = 2),
    regexp = "\\[model\\_DoseRate\\(\\)\\] Running MC calculation with 2 core\\(s\\) ...")

  ## compare this output with the one generate if we
  ## set data to NULL to avoid regression bugs
  expect_true(all(colnames(out) == colnames(model_DoseRate(data = NULL))))

  })
})
