test_that("gui_tga_curve validates columns and coerces to numeric", { df <- data.frame(T = c("25", "50", "100"), W = c("100.0", "99.8", "98.1")) out <- gui_tga_curve(df, "T", "W") expect_equal(names(out), c("temperature_C", "weight_pct")) expect_equal(out$temperature_C, c(25, 50, 100)) expect_error(gui_tga_curve(df, "nope", "W"), "not found") }) test_that("gui_tga_stages feeds into biocharkit::proximate_analysis correctly", { T <- seq(25, 800, by = 5) W <- ifelse(T <= 110, 100 - (5 / 110) * T, ifelse(T <= 650, 95 - (40 / (650 - 110)) * (T - 110), 55)) df <- data.frame(temp = T, wt = W) out <- gui_tga_stages(df, "temp", "wt") expect_equal(out$moisture_pct, 5, tolerance = 0.5) expect_equal(out$VM_pct, 40, tolerance = 0.5) expect_equal(out$ash_pct, 55, tolerance = 0.5) }) test_that("gui_tga_stages respects custom moisture_end/vm_end breakpoints", { T <- seq(25, 800, by = 5) W <- ifelse(T <= 150, 100 - (8 / 150) * T, ifelse(T <= 600, 92 - (37 / (600 - 150)) * (T - 150), 55)) df <- data.frame(temp = T, wt = W) out <- gui_tga_stages(df, "temp", "wt", moisture_end = 150, vm_end = 600) expect_equal(out$moisture_end_C, 150) expect_equal(out$vm_end_C, 600) expect_equal(out$moisture_pct, 8, tolerance = 0.5) }) test_that("gui_tga_stages_batch processes multiple samples and skips failures with a warning", { mk <- function(id, vm_center) { Tt <- seq(25, 800, by = 10) Ww <- 100 - 5 * (Tt > 110) - 40 / (1 + exp(-(Tt - vm_center) / 20)) data.frame(id = id, temp = Tt, wt = Ww) } good <- rbind(mk("A", 300), mk("B", 380)) bad <- data.frame(id = "C", temp = c(25, 50), wt = c(100, 99)) df <- rbind(good, bad) expect_warning(out <- gui_tga_stages_batch(df, "id", "temp", "wt"), "could not be processed") expect_equal(sort(unique(out$id)), c("A", "B")) }) test_that("gui_tga_stages_batch errors on missing columns", { df <- data.frame(id = "A", x = 1, y = 2) expect_error(gui_tga_stages_batch(df, "id", "temp", "wt"), "not found") }) test_that("gui_tga_kissinger returns a display-ready one-row params table", { df <- data.frame(beta = c(5, 10, 15, 20), Tpeak = c(320, 335, 344, 351)) res <- gui_tga_kissinger(df, "beta", "Tpeak") expect_equal(nrow(res$params), 1) expect_true(all(c("Ea_kJmol", "A_min1", "R2") %in% names(res$params))) expect_true(res$params$R2 > 0.99) expect_false(is.null(res$fit$model)) }) test_that("gui_tga_kissinger errors on missing columns", { df <- data.frame(x = 1:3, y = 1:3) expect_error(gui_tga_kissinger(df, "beta", "Tpeak"), "not found") })