Skip to content

Commit

Permalink
squash bugs highlighted by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Jan 11, 2024
1 parent 6df8dca commit 053f3e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions R/dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,6 @@ dist_spec <- function(distribution = c(
params_sd <- c(mean = mean_sd, sd = sd_sd)
} else if (distribution == "fixed") {
params_mean <- mean
params_sd <- 0
}
}
if (length(pmf) > 0) {
Expand All @@ -981,13 +980,16 @@ dist_spec <- function(distribution = c(
distribution <- "nonparametric"
parameters <- list(pmf = pmf)
} else {
if (length(params_sd) == 0) {
params_sd <- rep(0, length(params_mean))
}
parameters <- lapply(seq_along(params_mean), function(id) {
Normal(params_mean[id], params_sd[id])
})
names(parameters) <- natural_parameters(distribution)
names(parameters) <- natural_params(distribution)
parameters$max <- max
}
return(new_dist_spec(distribution, parameters))
return(new_dist_spec(parameters, distribution))
}

#' Creates a delay distribution as the sum of two other delay distributions.
Expand Down Expand Up @@ -1636,9 +1638,8 @@ Fixed <- function(value, max = Inf) {
##' pmf(c(0.1, 0.3, 0.2, 0.4))
##' pmf(c(0.1, 0.3, 0.2, 0.1, 0.1))
pmf <- function(mass) {
return(
new_dist_spec(parameters = list(pmf = mass / sum(mass)), "nonparametric")
)
params <- list(pmf = mass / sum(mass))
return(new_dist_spec(params, "nonparametric"))
}

##' Get the names of the natural parameters of a distribution
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-dist_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,5 @@ test_that("delay distributions can be specified in different ways", {
})

test_that("deprecated functions are deprecated", {
expect_deprecated(dist_spec(params_mean = 1.6, params_sd = 0.6, max = 19))
expect_deprecated(dist_spec(params_mean = c(1.6, 0.6), max = 19))
})

0 comments on commit 053f3e4

Please sign in to comment.