Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Dec 7, 2024
1 parent 39d8ca1 commit 1b56781
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions R/interpret.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ rules <- function(values, labels = NULL, name = NULL, right = TRUE) {
insight::format_error("Too many labels for the number of reference values!")
}

if (!is.numeric(values)) {
insight::format_error("Reference values must be numeric.")
}

if (length(values) == length(labels) - 1) {
if (is.unsorted(values)) {
insight::format_error("Reference values must be sorted.")
Expand Down
16 changes: 11 additions & 5 deletions tests/testthat/test-interpret.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ test_that("interpret generic", {
expect_error(rules(c(0.5), c("A", "B", "C")), "Too many")
expect_error(rules(c(0.5, 0.2, 0.7), c("A", "B", "C", "D")), "sorted")

expect_error(rules(1), NA)
expect_error(rules("a"), "must be numeric")


r1 <- rules(c(0, 1), labels = c("some", "few", "many"))
r2 <- rules(c(0, 1), labels = c("some", "few", "many"), right = FALSE)
Expand Down Expand Up @@ -96,11 +99,14 @@ test_that("interpret_rope", {


test_that("interpret_oddsratio", {
expect_equal(interpret_oddsratio(2)[1], "small")
expect_equal(interpret_oddsratio(c(1, 3))[1:2], c("very small", "small"))
expect_equal(interpret_oddsratio(c(1, 3), "cohen1988")[1:2], c("very small", "medium"))
expect_equal(interpret_oddsratio(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_oddsratio(0.6, "DUPA"), "must be")
# Chen 2010, table 1 row 6
OR <- c(1.4, 2.5, 4.4, 7.5)
p0 <- 0.06
expect_equal(interpret_oddsratio(OR, p0 = p0), c("very small", "small", "medium", "large"), ignore_attr = TRUE)
expect_equal(interpret_oddsratio(OR), c("very small", "medium", "large", "large"), ignore_attr = TRUE)

expect_equal(interpret_oddsratio(c(0.1, 0.5, 2, 10),
rules(3, c("A", "B"))), c("B", "A", "A", "B"), ignore_attr = TRUE)
})


Expand Down

0 comments on commit 1b56781

Please sign in to comment.