library(testthat) library(data.table) library(DTwrappers2) # Prepare the iris dataset data("iris") setDT(iris) describe("dt.max.numerics functionality", { it("computes maximum values correctly for each group", { max_values <- dt.max.numerics( dt.name = "iris", the.variables = c("Sepal.Length", "Sepal.Width"), grouping.variables = "Species" ) # Check if the result is a data.table expect_true(is.data.table(max_values), info = "Should return a data.table") }) it("handles non-numeric columns according to non.numeric.value parameter", { # Assuming iris dataset has a non-numeric column for testing iris$NonNumeric <- letters[1:nrow(iris)] max_values <- dt.max.numerics( dt.name = "iris", the.variables = c("Sepal.Length", "NonNumeric"), grouping.variables = "Species", non.numeric.value = "missing" ) # Non-numeric columns should be missing or the first entry based on non.numeric.value expect_true(all(is.na(max_values$NonNumeric) | max_values$NonNumeric == "a"), info = "Non-numeric values should be NA or the first entry") }) })