library(testthat) library(data.table) library(DTwrappers2) # Convert iris to a data.table once before the tests begin data("iris") setDT(iris) # Convert to data.table describe("dt.median.numerics functionality", { it("computes median values correctly with filter and grouping", { median_values <- dt.median.numerics( dt.name = "iris", the.filter = "Sepal.Length > 4 & Sepal.Length < 6", grouping.variables = "Species" ) # Convert the expected Species column to a factor to match the actual results expected_medians <- data.table( Species = factor(c("setosa", "versicolor", "virginica")), Sepal.Length = c(5.000 , 5.600 , 5.800), Sepal.Width = c(3.40 , 2.70 , 2.70), Petal.Length = c(1.50 , 4.00 , 5.10), Petal.Width = c(0.20 , 1.25 , 1.90) ) # Set the sorted attribute for the expected_medians to match median_values setattr(expected_medians, 'sorted', 'Species') # Check if the computed median values match the expected values expect_equal(median_values, expected_medians, info = "Computed medians should match expected medians") }) })