test_that("select_hits_cutoff selects by count of passing columns", {
  df <- data.frame(
    drug_name = c("DrugA", "DrugB", "DrugC"),
    A549 = c(-0.5, 0.2, -0.9),
    H1299 = c(-0.3, -0.1, -0.8)
  )
  out <- select_hits_cutoff(df, score_cols = c("A549", "H1299"),
    cutoff = 0, min_pass = 2)

  expect_equal(out$drug_name, c("DrugA", "DrugC"))
  expect_equal(out$n_pass, c(2L, 2L))
})

test_that("select_hits_cutoff drops rows with missing scores", {
  df <- data.frame(
    drug_name = c("DrugA", "DrugB"),
    A549 = c(-0.5, NA),
    H1299 = c(-0.3, -0.8)
  )
  out <- select_hits_cutoff(df, score_cols = c("A549", "H1299"),
    cutoff = 0, min_pass = 2)
  expect_equal(out$drug_name, "DrugA")
})

test_that("select_hits_cutoff errors on unknown columns", {
  df <- data.frame(drug_name = "D1", A549 = -0.5)
  expect_error(
    select_hits_cutoff(df, score_cols = c("A549", "MISSING")),
    "not found"
  )
})

test_that("select_hits_sigma selects in a direction", {
  df <- data.frame(
    drug_name = paste0("Drug", 1:6),
    zscore_delta_auc = c(-3.4, -1.2, 0.1, 0.5, 1.1, -2.8)
  )
  less <- select_hits_sigma(df, n_sigma = 2, direction = "less")
  expect_equal(less$drug_name, c("Drug1", "Drug6"))

  greater <- select_hits_sigma(df, n_sigma = 2, direction = "greater")
  expect_equal(nrow(greater), 0)
})

test_that("select_hits_sigma can standardise raw scores", {
  # one strong outlier among five near-zero values crosses the 2-sigma threshold
  df <- data.frame(
    drug_name = paste0("D", 1:6),
    score = c(-100, 0, 0, 0, 0, 0)
  )
  out <- select_hits_sigma(df, score_col = "score", n_sigma = 2,
    direction = "less", standardize = TRUE)
  expect_equal(out$drug_name, "D1")
})
