Skip to content

Commit

Permalink
Ensure alpha < beta for uniform prior
Browse files Browse the repository at this point in the history
  • Loading branch information
gowerc committed Feb 5, 2024
1 parent c587a69 commit 1b6ffe5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/Prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ prior_none <- function() {
#'
#' @export
prior_uniform <- function(alpha, beta) {
assert_that(
alpha < beta,
msg = "`alpha`` must be less than `beta`"
)
Prior(
parameters = list(alpha = alpha, beta = beta),
display = "uniform(alpha = {alpha}, beta = {beta})",
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-Prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ test_that("Invalid prior parameters are rejected", {
regexp = "Invalid.*`beta`"
)

expect_error(
prior_uniform(10, 9),
regexp = "`alpha`` must be less than `beta`"
)


# Ensure that validation doesn't wrongly reject priors with no user specified parameters
expect_s4_class(prior_none(), "Prior")
Expand Down

0 comments on commit 1b6ffe5

Please sign in to comment.