Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jun 27, 2023
1 parent c8f45ed commit 3d90fc9
Show file tree
Hide file tree
Showing 25 changed files with 332 additions and 316 deletions.
39 changes: 0 additions & 39 deletions R/interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,3 @@ setMethod(
)
}
)

# Helpers ======================================================================
#' Simplify
#'
#' Reduces the result of `credible()` or `hpdi()` to a `matrix`.
#' @param x A [`list`] of [`matrix`] (returned by `credible()` or `hpdi()`)
#' @return A [`data.frame`].
#' @author N. Frerebeau
#' @keywords internal
#' @noRd
bind_intervals <- function(x) {
hpd <- do.call(rbind.data.frame, x)
rownames(hpd) <- NULL
n <- vapply(X = x, FUN = nrow, FUN.VALUE = integer(1))
hpd <- data.frame(name = rep(names(x), times = n), hpd)
hpd
}

#' Interval Matching
#'
#' Tests if the values of an MCMC sample belong to an interval.
#' @param x A [`numeric`] vector (MCMC sample).
#' @param y A [`matrix`] (returned by `credible()` or `hpdi()`).
#' @return A [`logical`] vector.
#' @author N. Frerebeau
#' @keywords internal
#' @noRd
is_credible <- function(x, y) {
tmp <- apply(
X = y,
MARGIN = 1,
FUN = function(i, mcmc) {
mcmc >= i[[1L]] & mcmc <= i[[2L]]
},
mcmc = x,
simplify = TRUE
)
rowSums(tmp) > 0
}
Binary file added inst/tinytest/_snaps/activity.rds
Binary file not shown.
Binary file added inst/tinytest/_snaps/occurrence.rds
Binary file not shown.
Binary file added inst/tinytest/_snaps/tempo.rds
Binary file not shown.
48 changes: 25 additions & 23 deletions inst/tinytest/_tinysnapshot/plot_activity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions inst/tinytest/_tinysnapshot/plot_event.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 18 additions & 18 deletions inst/tinytest/_tinysnapshot/plot_event_cred.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions inst/tinytest/_tinysnapshot/plot_event_decr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 19 additions & 19 deletions inst/tinytest/_tinysnapshot/plot_event_hdr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions inst/tinytest/_tinysnapshot/plot_event_incr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions inst/tinytest/_tinysnapshot/plot_event_inter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3d90fc9

Please sign in to comment.