From 63b304de8ffb9936f0c60499a08bf9023e3f37b9 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 10 Jun 2024 17:08:09 +0100 Subject: [PATCH] added unit tests for .clean_epidist_params and create_epidist_prob_dist for exponential dist --- .../testthat/test-create_epidist_prob_dist.R | 16 ++++++++++ tests/testthat/test-epidist_utils.R | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/testthat/test-create_epidist_prob_dist.R b/tests/testthat/test-create_epidist_prob_dist.R index bea01a330..89f454399 100644 --- a/tests/testthat/test-create_epidist_prob_dist.R +++ b/tests/testthat/test-create_epidist_prob_dist.R @@ -94,6 +94,22 @@ test_that("create_epidist_prob_dist works for poisson", { ) }) +test_that("create_epidist_prob_dist works for exponential", { + res <- create_epidist_prob_dist( + prob_dist = "exp", + prob_dist_params = c(rate = 2), + discretise = FALSE, + truncation = NA + ) + + expect_s3_class(res, "distribution") + expect_identical(family(res), "exponential") + expect_identical( + distributional::parameters(res), + data.frame(rate = 2) + ) +}) + test_that("create_epidist_prob_dist works for discrete gamma", { res <- create_epidist_prob_dist( prob_dist = "gamma", diff --git a/tests/testthat/test-epidist_utils.R b/tests/testthat/test-epidist_utils.R index f4248ca85..2062d0d71 100644 --- a/tests/testthat/test-epidist_utils.R +++ b/tests/testthat/test-epidist_utils.R @@ -239,6 +239,36 @@ test_that(".clean_epidist_params fails when pois parameters are incorrect", { ) }) +test_that(".clean_epidist_params works as expected for exp", { + params <- .clean_epidist_params( + prob_dist = "exp", + prob_dist_params = c(rate = 2) + ) + expect_identical(params, c(rate = 2)) + + params <- .clean_epidist_params( + prob_dist = "exp", + prob_dist_params = c(lambda = 2) + ) + expect_identical(params, c(rate = 2)) + + params <- .clean_epidist_params( + prob_dist = "exp", + prob_dist_params = c(mean = 0.5) + ) + expect_identical(params, c(rate = 2)) +}) + +test_that(".clean_epidist_params fails when exp parameters are incorrect", { + expect_error( + .clean_epidist_params( + prob_dist = "exp", + prob_dist_params = c(means = 1) + ), + regexp = "Invalid parameterisation for exp distribution" + ) +}) + test_that(".clean_epidist_params fails as expected", { expect_error( .clean_epidist_params(