# WARNING - Generated by {fusen} from dev/flat_kwb_simulate_inflow.Rmd: do not edit by hand # nolint: line_length_linter.


test_that("distribution_repeater works correctly", {
  # Test with default parameters
  result <- distribution_repeater(func = runif)
  expect_equal(nrow(result), 3650)
  expect_equal(length(unique(result$repeatID)), 10)
  expect_equal(length(unique(result$eventID)), 365)

  # Test with custom number_of_repeatings and number_of_events
  result <- distribution_repeater(
    number_of_repeatings = 2,
    number_of_events = 10,
    func = runif
  )
  expect_equal(nrow(result), 20)
  expect_equal(length(unique(result$repeatID)), 2)
  expect_equal(length(unique(result$eventID)), 10)

  # Test with number_of_events = 1: must still return the long data.frame
  # (number_of_repeatings defaults to 10, so 10 rows / 10 repeatIDs / 1 eventID)
  result <- distribution_repeater(number_of_events = 1, func = runif)
  expect_s3_class(result, "data.frame")
  expect_named(result, c("repeatID", "eventID", "values"))
  expect_equal(nrow(result), 10)
  expect_equal(length(unique(result$repeatID)), 10)
  expect_equal(length(unique(result$eventID)), 1)

  # number_of_events < 1 is meaningless and must fail early and clearly
  expect_error(
    distribution_repeater(number_of_events = 0, func = runif),
    "positive integer"
  )
  expect_error(
    distribution_repeater(number_of_events = -1, func = runif),
    "positive integer"
  )

  # Test with different distribution function (rnorm)
  result <- distribution_repeater(func = rnorm, mean = 0, sd = 1)
  expect_equal(nrow(result), 3650)
  expect_equal(length(unique(result$repeatID)), 10)
  expect_equal(length(unique(result$eventID)), 365)

  # Test with additional parameters for distribution function
  result <- distribution_repeater(func = runif, min = 1, max = 10)
  expect_equal(nrow(result), 3650)
  expect_equal(length(unique(result$repeatID)), 10)
  expect_equal(length(unique(result$eventID)), 365)
  expect_true(all(result$values >= 1 & result$values <= 10, na.rm = TRUE))
})
