# Test for corrCI_sa function

test_that("corrCI_sa handles basic input", {
  set.seed(42)
  x <- rnorm(15)
  y <- rnorm(15)
  result <- corrCI_sa(x, y)

  expect_s3_class(result, "corrCI_sa")
  expect_type(result, "list")
  expect_equal(result$conf.level, 0.95)
  expect_true(result$lower < result$estimate)
  expect_true(result$upper > result$estimate)
})

test_that("corrCI_sa handles different conf.level", {
  set.seed(42)
  x <- rnorm(15)
  y <- rnorm(15)
  result <- corrCI_sa(x, y, conf.level = 0.99)

  expect_equal(result$conf.level, 0.99)
})

test_that("corrCI_sa rejects invalid input", {
  expect_error(corrCI_sa("a", 1:15))
  expect_error(corrCI_sa(1:15, 1:10))
  expect_error(corrCI_sa(1:2, 1:2))
  expect_error(corrCI_sa(1:15, 1:15, conf.level = 1.5))
})

test_that("corrCI_sa returns correct structure", {
  set.seed(42)
  x <- rnorm(15)
  y <- rnorm(15)
  result <- corrCI_sa(x, y)

  expect_true("lower" %in% names(result))
  expect_true("upper" %in% names(result))
  expect_true("estimate" %in% names(result))
  expect_true("conf.level" %in% names(result))
  expect_true("method" %in% names(result))
  expect_true("iterations" %in% names(result))
})