Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 2, 2023
1 parent b717b90 commit 81ba62d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions R/hdi.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ hdi.get_predicted <- function(x, ...) {

if (window_size < 2) {
if (verbose) {
insight::format_message("`ci` is too small or x does not contain enough data points, returning NAs.")
insight::format_alert("`ci` is too small or x does not contain enough data points, returning NAs.")
}
return(data.frame(
"CI" = ci,
Expand All @@ -395,7 +395,7 @@ hdi.get_predicted <- function(x, ...) {

if (nCIs < 1) {
if (verbose) {
insight::format_message("`ci` is too large or x does not contain enough data points, returning NAs.")
insight::format_alert("`ci` is too large or x does not contain enough data points, returning NAs.")
}
return(data.frame(
"CI" = ci,
Expand All @@ -413,7 +413,7 @@ hdi.get_predicted <- function(x, ...) {
if (n_candies > 1) {
if (any(diff(sort(min_i)) != 1)) {
if (verbose) {
insight::format_message("Identical densities found along different segments of the distribution, choosing rightmost.")
insight::format_alert("Identical densities found along different segments of the distribution, choosing rightmost.")
}
min_i <- max(min_i)
} else {
Expand Down
1 change: 1 addition & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ print.bayesfactor_parameters <- function(x, digits = 3, log = FALSE, ...) {
cat(paste0(colnames(formatted_table), ": "))
}
cat(formatted_table[1, 1])
cat("\n")
} else {
# print for data frame

Expand Down
21 changes: 10 additions & 11 deletions tests/testthat/test-hdi.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ test_that("hdi", {
skip_if_not_or_load_if_installed("httr")
skip_if_not_or_load_if_installed("BayesFactor")

expect_equal(hdi(distribution_normal(1000), ci = .90)$CI_low[1], -1.64, tolerance = 0.02)
expect_equal(nrow(hdi(distribution_normal(1000), ci = c(.80, .90, .95))), 3, tolerance = 0.01)
expect_equal(hdi(distribution_normal(1000), ci = 0.90)$CI_low[1], -1.64, tolerance = 0.02)
expect_equal(nrow(hdi(distribution_normal(1000), ci = c(0.80, 0.90, 0.95))), 3, tolerance = 0.01)
expect_equal(hdi(distribution_normal(1000), ci = 1)$CI_low[1], -3.29, tolerance = 0.02)
expect_equal(nchar(capture.output(print(hdi(distribution_normal(1000))))), 22)
expect_equal(length(capture.output(print(hdi(distribution_normal(1000), ci = c(.80, .90))))), 5)
expect_identical(nchar(capture.output(print(hdi(distribution_normal(1000))))), 22L)
expect_length(capture.output(print(hdi(distribution_normal(1000), ci = c(0.80, 0.90)))), 5)


expect_warning(hdi(c(2, 3, NA)))
expect_warning(hdi(c(2, 3)))
expect_warning(hdi(distribution_normal(1000), ci = 0.0000001))
expect_warning(hdi(distribution_normal(1000), ci = 950))
expect_warning(hdi(c(0, 0, 0)))
expect_message(hdi(c(2, 3, NA)))
expect_message(hdi(c(2, 3)))
expect_message(hdi(distribution_normal(1000), ci = 0.0000001))
expect_message(hdi(distribution_normal(1000), ci = 950))
expect_message(hdi(c(0, 0, 0)))
})


Expand Down Expand Up @@ -65,7 +64,7 @@ test_that("ci - BayesFactor", {
skip_if_not_or_load_if_installed("httr")
skip_if_not_or_load_if_installed("BayesFactor")

mod_bf <- proportionBF(y = 15, N = 25, p = .5)
mod_bf <- proportionBF(y = 15, N = 25, p = 0.5)
p_bf <- insight::get_parameters(mod_bf)

expect_equal(
Expand Down

0 comments on commit 81ba62d

Please sign in to comment.