test_that("theorem-based row-column design is generated", {
  res <- generate_2fi_rowcol(s = 3, p = 1, q = 1, n = 2, mode = "auto")
  
  expect_type(res, "list")
  expect_s3_class(res$design, "data.frame")
  expect_equal(nrow(res$design), 3^(1 + 1))
  expect_true(all(c("Row", "Col", "F1", "F2") %in% names(res$design)))
})

test_that("generator matrix has expected dimensions", {
  G <- build_G(s = 3, p = 1, q = 1, n = 2)
  
  expect_true(is.matrix(G))
  expect_equal(dim(G), c(2L, 2L))
})

test_that("aliasing diagnostic returns expected fields", {
  G <- build_G(s = 3, p = 1, q = 1, n = 2)
  res <- generate_row_column_design(G, s = 3, p = 1, q = 1)
  ev <- eval_2fi_from_design(res$design, s = 3)
  
  expect_type(ev, "list")
  expect_true(all(c("main_ok", "unconf_2fi_num") %in% names(ev)))
  expect_type(ev$main_ok, "logical")
  expect_type(ev$unconf_2fi_num, "integer")
})

test_that("search rejects non-prime level numbers", {
  expect_error(
    search_2fi_optimal_G_k23(s = 4, p = 1, q = 1, n = 4, max_tries = 1),
    "s must be prime"
  )
})