diff --git a/tests/testthat/test-datatype.R b/tests/testthat/test-datatype.R index 3066ce4f2..bf2e01e00 100644 --- a/tests/testthat/test-datatype.R +++ b/tests/testthat/test-datatype.R @@ -224,12 +224,18 @@ test_that("contains_* functions for datatype work", { }) test_that("Enum", { - expect_identical( - as_polars_series(c("z", "z", "k", "a"))$ - cast(pl$Enum(c("z", "k", "a")))$ - to_r(), - factor(c("z", "z", "k", "a")) - ) + # Generate 100 random data frames with random + # orders for levels. They should always match + for (i in 1:100) { + expected_levels = sample(letters, length(letters)) + expected_values = sample(letters, length(letters)) + expect_identical( + as_polars_series(expected_values)$ + cast(pl$Enum(expected_levels))$ + to_r(), + factor(expected_values, levels = expected_levels) + ) + } expect_grepl_error(pl$Enum(), "missing") expect_grepl_error(pl$Enum(1), "invalid series dtype")