test_that("illustrative budget builds reproducible PAM accounts", { budget <- agri_pam_example("budget") expect_s3_class(budget, "data.frame") expect_equal(nrow(budget), 28) x <- agri_pam_example() expect_s3_class(x, "agri_pam") expect_equal(pam_values(x)$id, c("Paddy", "Wheat", "Chickpea", "Mustard")) paddy <- pam_values(x)[1, ] expect_equal(paddy$private_revenue, 123400) expect_equal(paddy$private_tradable_inputs, 28300) expect_equal(paddy$private_domestic_factors, 67500) expect_equal(paddy$private_profit, 27600) expect_equal(paddy$social_revenue, 127100) expect_equal(paddy$social_profit, 25520) }) test_that("budget category aliases and grouping work", { budget <- data.frame( farm = c("A", "A", "A", "B", "B", "B"), category = c( "Revenue", "Tradable Inputs", "Domestic Factors", "output", "tradable", "domestic" ), quantity = 1, pp = c(100, 25, 45, 120, 30, 50), sp = c(110, 30, 40, 125, 35, 45) ) x <- pam_from_budget( budget, "quantity", "pp", "sp", "category", id = "farm" ) expect_equal(pam_values(x)$private_profit, c(30, 40)) expect_equal(pam_values(x)$social_profit, c(40, 45)) expect_error( pam_from_budget( transform(budget, category = "unknown"), "quantity", "pp", "sp", "category", id = "farm" ), "Unrecognised" ) }) test_that("parity prices implement import and export adjustments", { expect_equal( parity_price(300, 83, transport = 1200, handling = 300, direction = "import"), 26400 ) expect_equal( parity_price(300, 83, transport = 1200, handling = 300, direction = "export"), 23400 ) expect_equal(parity_price(c(10, 20), 2), c(20, 40)) expect_error(parity_price(1, exchange_rate = 0), "strictly positive") expect_error( parity_price(1, exchange_rate = 1, transport = 2, direction = "export"), "negative" ) })