test_that("nrm_response_curve fits quadratic", { data(nrm_example, package = "NRMstatsML") rc <- nrm_response_curve(nrm_example, input_var = "N", response_var = "crop_yield", type = "quadratic") expect_s3_class(rc, "nrm_response_curve") expect_equal(rc$type, "quadratic") expect_true(is.numeric(rc$r_squared)) }) test_that("nrm_response_curve fits linear", { data(nrm_example, package = "NRMstatsML") rc <- nrm_response_curve(nrm_example, input_var = "N", response_var = "crop_yield", type = "linear") expect_equal(rc$type, "linear") expect_true(is.numeric(rc$r_squared)) }) test_that("nrm_optimize_input works on quadratic curve", { data(nrm_example, package = "NRMstatsML") rc <- nrm_response_curve(nrm_example, input_var = "N", response_var = "crop_yield", type = "quadratic") opt <- nrm_optimize_input(rc, price_ratio = 0.5) expect_s3_class(opt, "nrm_optimize_input") expect_true(is.numeric(opt$biophysical_optimum)) expect_equal(opt$price_ratio, 0.5) }) test_that("nrm_optimize_input errors on wrong class", { expect_error(nrm_optimize_input(list()), "class 'nrm_response_curve'") }) test_that("nrm_response_curve rejects unknown type", { data(nrm_example, package = "NRMstatsML") expect_error( nrm_response_curve(nrm_example, input_var = "N", response_var = "crop_yield", type = "exponential"), "should be one of" ) })