test_that("normalisation respects direction", { x <- data.frame(a = c(1, 2, 3), b = c(1, 2, 3)) z <- normalize_indicators(x, c("+", "-")) expect_equal(unname(z[, 1]), c(0, 0.5, 1)) expect_equal(unname(z[, 2]), c(1, 0.5, 0)) expect_equal(unname(normalize_indicators(x, 1, "ratio")[, 1]), c(0.5, 1, 1.5)) }) test_that("entropy weights sum to one and favour dispersion", { w <- entropy_weights(data.frame(a = c(0, 0.5, 1), b = c(0.4, 0.5, 0.6))) expect_equal(sum(w), 1) expect_gt(w[["a"]], w[["b"]]) }) test_that("composite index ranks correctly", { x <- data.frame(good = c(1, 2, 3), bad = c(3, 2, 1)) ci <- composite_index(x, c("+", "-")) expect_equal(ci$scores$rank, c(3, 2, 1)) cg <- composite_index(x, c("+", "-"), aggregation = "geometric", weights = c(1, 1)) expect_equal(cg$scores$rank, c(3, 2, 1)) expect_error(composite_index(x, method = "zscore", aggregation = "geometric")) expect_output(print(ci), "Composite") }) test_that("eco-efficiency ratio and DEA", { r <- eco_efficiency_ratio(c(10, 20), data.frame(p = c(2, 2)), weights = 1) expect_equal(r$ee_p, c(5, 10)) v <- c(10, 20, 15) p <- data.frame(p1 = c(5, 5, 10), p2 = c(2, 2, 4)) d <- eco_efficiency_dea(v, p) expect_equal(d$efficiency, c(0.5, 1, 0.375), tolerance = 1e-6) dv <- eco_efficiency_dea(v, p, rts = "vrs") expect_true(all(dv$efficiency >= d$efficiency - 1e-8)) expect_error(eco_efficiency_dea(c(0, 1, 2), p)) })