From 1b5678105520f6499cb4b0a0e7bd5a5e86179255 Mon Sep 17 00:00:00 2001 From: "Mattan S. Ben-Shachar" Date: Sat, 7 Dec 2024 21:16:30 +0200 Subject: [PATCH] fix tests --- R/interpret.R | 4 ++++ tests/testthat/test-interpret.R | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/R/interpret.R b/R/interpret.R index c2afe096..e63cad99 100644 --- a/R/interpret.R +++ b/R/interpret.R @@ -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.") diff --git a/tests/testthat/test-interpret.R b/tests/testthat/test-interpret.R index b385b160..d8cd603a 100644 --- a/tests/testthat/test-interpret.R +++ b/tests/testthat/test-interpret.R @@ -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) @@ -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) })