test_that("sensitivity scenarios preserve the base case at zero", { x <- agri_pam_example() s <- pam_sensitivity( x, "private_revenue", changes = c(-0.1, 0, 0.1), index = "Paddy" ) expect_s3_class(s, "agri_pam_sensitivity") expect_equal(nrow(s$results), 3) expect_equal(s$results$private_profit[2], pam_values(x)$private_profit[1]) expect_equal(s$results$social_profit, rep(pam_values(x)$social_profit[1], 3)) expect_equal(s$results$scenario_value[3], 1.1 * 123400) }) test_that("profit and DRC switching values are found", { x <- agri_pam_example() private_switch <- switching_value( x, "private_revenue", metric = "private_profit", index = "Paddy" ) expect_true(private_switch$found) expect_equal(private_switch$change, -27600 / 123400, tolerance = 1e-6) expect_equal(private_switch$achieved, 0, tolerance = 1e-4) drc_switch <- switching_value( x, "social_revenue", metric = "drc", index = "Paddy" ) expect_true(drc_switch$found) expect_equal(drc_switch$change, -25520 / 127100, tolerance = 1e-6) expect_equal(drc_switch$achieved, 1, tolerance = 1e-6) }) test_that("switching value reports an unreachable target", { x <- agri_pam_example() expect_warning( result <- switching_value( x, "private_revenue", metric = "drc", target = 0.5, interval = c(-0.5, 0.5), index = "Paddy" ), "No switching value" ) expect_false(result$found) expect_true(is.na(result$change)) })