From 1b6ffe5029b0cb9ee65fc5685e62bf11b8ad7f6c Mon Sep 17 00:00:00 2001 From: gowerc Date: Mon, 5 Feb 2024 16:26:06 +0000 Subject: [PATCH] Ensure alpha < beta for uniform prior --- R/Prior.R | 4 ++++ tests/testthat/test-Prior.R | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/R/Prior.R b/R/Prior.R index 1a7d4300..8ef9f09a 100755 --- a/R/Prior.R +++ b/R/Prior.R @@ -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})", diff --git a/tests/testthat/test-Prior.R b/tests/testthat/test-Prior.R index 4266d441..e5536f34 100644 --- a/tests/testthat/test-Prior.R +++ b/tests/testthat/test-Prior.R @@ -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")