testthat::test_that("pareto_2d identifies Pareto points when minimizing both", { x <- c(1,2,3,4) y <- c(4,3,2,1) res <- pareto_2d(x, y, x_bigger_better = FALSE, y_bigger_better = FALSE) # All points should be Pareto testthat::expect_true(all(res)) }) testthat::test_that("pareto_2d identifies Pareto points when maximizing both", { x <- c(1,2,3,4) y <- c(1,2,3,4) res <- pareto_2d(x, y, x_bigger_better = TRUE, y_bigger_better = TRUE) # Only the best point survives testthat::expect_equal(which(res), 4) }) testthat::test_that("pareto_2d works with mixed optimization directions", { x <- c(1,2,3) y <- c(3,2,1) res <- pareto_2d(x, y, x_bigger_better = FALSE, y_bigger_better = TRUE) # first point should dominate others testthat::expect_true(res[1]) testthat::expect_false(res[2]) testthat::expect_false(res[3]) }) testthat::test_that("pareto_2d handles NA values", { x <- c(1,2,NA,3) y <- c(3,2,1,NA) res <- pareto_2d(x, y, x_bigger_better = FALSE, y_bigger_better = FALSE) # NAs should be treated as dominated testthat::expect_false(res[3]) testthat::expect_false(res[4]) }) testthat::test_that("plot_pareto returns expected structure", { set.seed(123) df <- data.frame( obj1 = runif(20), obj2 = runif(20) ) res <- plot_pareto(df,"obj1","obj2") testthat::expect_true(is.list(res)) testthat::expect_s3_class(res$plot,"ggplot") testthat::expect_true(is.data.frame(res$pareto_points)) testthat::expect_true(is.data.frame(res$all)) }) testthat::test_that("plot_pareto works with all direction combinations", { set.seed(42) df <- data.frame( x = runif(30), y = runif(30) ) combos <- expand.grid( x_bigger_better = c(TRUE,FALSE), y_bigger_better = c(TRUE,FALSE) ) for(i in seq_len(nrow(combos))){ res <- plot_pareto( df, "x", "y", x_bigger_better = combos$x_bigger_better[i], y_bigger_better = combos$y_bigger_better[i] ) testthat::expect_s3_class(res$plot,"ggplot") testthat::expect_true(nrow(res$pareto_points) >= 1) } })