R/testthat-helpers.R
raw| 1 | |
| 2 | expect_same_elements <- function(lhs, rhs) { |
| 3 | |
| 4 | if (!requireNamespace("testthat", quietly = TRUE)) |
| 5 | stop("testthat not available for testing") |
| 6 | |
| 7 | if (is.list(lhs) && is.list(rhs)) { |
| 8 | lhs <- lhs[order(names(lhs))] |
| 9 | rhs <- rhs[order(names(rhs))] |
| 10 | return(testthat::expect_equal(!!lhs, !!rhs)) |
| 11 | } |
| 12 | |
| 13 | if (packageVersion("testthat") > "2.2.0") |
| 14 | testthat::expect_setequal(!!lhs, !!rhs) |
| 15 | else |
| 16 | testthat::expect_setequal(lhs, rhs) |
| 17 | |
| 18 | } |