test_that("fit_isotherm_batch fits each group and returns one row per group", { df <- data.frame( id = rep(c("A", "B"), each = 6), Ce = rep(c(2, 5, 10, 20, 35, 50), 2), qe = c(0.8, 1.6, 2.3, 3.0, 3.6, 4.0, 0.5, 1.0, 1.6, 2.2, 2.7, 3.0) ) res <- fit_isotherm_batch(df, "id", "Ce", "qe", model = "langmuir") expect_equal(nrow(res), 2) expect_true(all(c("id", "Qmax", "KL", "R2") %in% names(res))) expect_true(all(res$R2 > 0.9)) }) test_that("fit_isotherm_batch skips failing groups with a warning", { df <- data.frame( id = c(rep("A", 6), rep("bad", 2)), Ce = c(2, 5, 10, 20, 35, 50, 1, 2), qe = c(0.8, 1.6, 2.3, 3.0, 3.6, 4.0, 1, 1) ) expect_warning(res <- fit_isotherm_batch(df, "id", "Ce", "qe", model = "langmuir"), "could not be fit") expect_equal(nrow(res), 1) expect_equal(res$id, "A") }) test_that("fit_isotherm_batch errors when no group can be fit", { df <- data.frame(id = "only_one", Ce = 5, qe = 1) expect_error(suppressWarnings(fit_isotherm_batch(df, "id", "Ce", "qe", model = "langmuir")), "No groups") }) test_that("fit_kinetics_batch fits each group and returns one row per group", { df <- data.frame( id = rep(c("A", "B"), each = 6), t = rep(c(5, 15, 30, 60, 120, 240), 2), qt = c(1.2, 2.1, 2.9, 3.6, 4.0, 4.2, 0.8, 1.5, 2.0, 2.5, 2.8, 3.0) ) res <- fit_kinetics_batch(df, "id", "t", "qt", model = "pso") expect_equal(nrow(res), 2) expect_true(all(c("id", "qe", "k2", "R2") %in% names(res))) }) test_that("batch functions error on missing columns", { df <- data.frame(id = "A", Ce = 1, qe = 1) expect_error(fit_isotherm_batch(df, "id", "Ce", "missing_col", model = "langmuir"), "not found") })