Skip to content

Commit

Permalink
fix warning checks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsjanzen committed May 15, 2024
1 parent 797f1f6 commit 8479bf7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
4 changes: 2 additions & 2 deletions tests/testthat/test_cla_secsse_ml_func_def_pars.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("multiplication works", {
cond <- 'proper_cond'
root_state_weight <- 'proper_weights'
sampling_fraction <- c(1, 1, 1)
model <- expect_message(expect_warning(cla_secsse_ml_func_def_pars(
model <- expect_warning(cla_secsse_ml_func_def_pars(
phylotree,
traits,
num_concealed_states,
Expand All @@ -63,7 +63,7 @@ test_that("multiplication works", {
optimmethod,
num_cycles = 1,
verbose = 0
)))
))

expect_equal(model$ML, -136.5926599)
expect_length(model, 3)
Expand Down
15 changes: 11 additions & 4 deletions tests/testthat/test_hisse.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ test_that("secsse gives the same result as hisse", {
root_state_weight <- "maddison_weights"
cond <- "noCondit"

testthat::expect_warning(

y <- secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states = num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction)

)
cond <- "maddison_cond"
testthat::expect_warning(
y1 <- round(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
Expand All @@ -43,20 +48,21 @@ test_that("secsse gives the same result as hisse", {
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction)
), 4)
)

## Now with different sampling_fraction

sampling_fraction <- c(0.8, 1)

y2 <- round(as.numeric(secsse_loglik(parameter = toCheck,
y2 <- testthat::expect_warning(round(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction)
), 4)
), 4))

testthat::expect_equal(-237.8611, y1, tolerance = 0.001)
testthat::expect_equal(-243.8611, y2, tolerance = 0.001)
Expand All @@ -65,14 +71,15 @@ test_that("secsse gives the same result as hisse", {
.Platform$OS.type == "windows") {
testthat::skip_on_cran()

z4 <- as.numeric(secsse_loglik(parameter = toCheck,
z4 <- testthat::expect_warning(
as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states = num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
num_threads = 4))
num_threads = 4)))
testthat::expect_equal(y2, z4, tolerance = 1e-4)
# is different LL, diff 0.0118
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_integration_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ test_that("loglik for different integrators", {
root_state_weight <- "maddison_weights"
cond <- "noCondit"

loglik1 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik1 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction)
)
))

for (integ_method in c("odeint::runge_kutta_cash_karp54",
"odeint::runge_kutta_fehlberg78",
"odeint::runge_kutta_dopri5",
"odeint::bulirsch_stoer",
"odeint::runge_kutta4")) {
loglik2 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik2 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
method = integ_method))
method = integ_method)))
testthat::expect_equal(loglik1, loglik2)
}
})
7 changes: 3 additions & 4 deletions tests/testthat/test_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("normal plotting", {
helper_function <- function(x) {
return(sum(x[c(5, 7)]) / sum(x)) # normalized by total sum, just in case.
}
testthat::expect_message(
testthat::expect_warning(
px <- plot_state_exact(parameters = params,
phy = phy,
traits = traits,
Expand Down Expand Up @@ -57,7 +57,6 @@ test_that("cla plotting", {
root_state_weight <- "proper_weights"
sampling_fraction <- c(1, 1, 1)

testthat::expect_message(
testthat::expect_warning(
model_R <- cla_secsse_ml(
phylotree,
Expand All @@ -76,13 +75,13 @@ test_that("cla plotting", {
optimmethod,
num_cycles = 1,
verbose = FALSE)
))
)

helper_function <- function(x) {
return(sum(x[c(10, 13, 16)]) / sum(x))
}

testthat::expect_message(
testthat::expect_warning(
px <- secsse::plot_state_exact(parameters = model_R$MLpars,
phy = phylotree,
traits = traits,
Expand Down
33 changes: 18 additions & 15 deletions tests/testthat/test_secsse_ct.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ test_that("the loglik for the complete tree", {
root_state_weight <- "maddison_weights"
cond <- "noCondit"

loglik1 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik1 <- testthat::expect_warning(
as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
Expand All @@ -26,15 +27,17 @@ test_that("the loglik for the complete tree", {
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = TRUE)
)
loglik2 <- as.numeric(secsse_loglik(parameter = toCheck,
))
loglik2 <- testthat::expect_warning(
as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction)
)
)
# check that the likelihood for a specifically complete tree without
# extinct lineages with 0 extinction
Expand All @@ -43,25 +46,25 @@ test_that("the loglik for the complete tree", {
testthat::expect_equal(loglik1, loglik2)

toCheck[[2]][] <- 0.05
loglik3 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik3 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = TRUE)
is_complete_tree = TRUE))
)
loglik4 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik4 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = FALSE)
is_complete_tree = FALSE))
)
# check that when the extinction rate is not zero,
# the likelihood of treating the tree as
Expand All @@ -79,15 +82,15 @@ test_that("the loglik for the complete tree", {
# out <- DDD::dd_sim(pars = c(0.4, 0.1, 40), age = 15)
# phy <- out$tas
# traits <- sample(c(0,1),ape::Ntip(phy),replace = T)
loglik5 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik5 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = TRUE))
is_complete_tree = TRUE)))
testthat::expect_equal(loglik5,
-303.4003,
tolerance = 1E-4) # TJ: hardcoded modified LL
Expand All @@ -101,7 +104,7 @@ test_that("the loglik for the complete tree", {
parameter <- toCheck
parameter[[1]] <- lambdas

loglik7 <- secsse_loglik(parameter = parameter,
loglik7 <- testthat::expect_warning(secsse_loglik(parameter = parameter,
phy = phy,
traits = traits,
num_concealed_states = num_concealed_states,
Expand All @@ -111,13 +114,13 @@ test_that("the loglik for the complete tree", {
setting_calculation = NULL,
see_ancestral_states = FALSE,
loglik_penalty = 0,
is_complete_tree = TRUE)
is_complete_tree = TRUE))
testthat::expect_equal(loglik7, loglik5) # not true ?

# Parallel code doesn't work on CI
skip_on_cran()
skip_on_ci()
loglik6 <- as.numeric(secsse_loglik(parameter = toCheck,
loglik6 <- testthat::expect_warning(as.numeric(secsse_loglik(parameter = toCheck,
phy = phy,
traits = traits,
num_concealed_states =
Expand All @@ -126,17 +129,17 @@ test_that("the loglik for the complete tree", {
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = TRUE,
num_threads = 4))
num_threads = 4)))
testthat::expect_equal(loglik6, loglik5, tolerance = 1E-4)

loglik8 <- secsse_loglik(parameter = parameter,
loglik8 <- testthat::expect_warning(secsse_loglik(parameter = parameter,
phy = phy,
traits = traits,
num_concealed_states = num_concealed_states,
cond = cond,
root_state_weight = root_state_weight,
sampling_fraction = sampling_fraction,
is_complete_tree = TRUE,
num_threads = 4)
num_threads = 4))
testthat::expect_equal(loglik8, loglik7, tolerance = 1e-5)
})
3 changes: 1 addition & 2 deletions tests/testthat/test_secsse_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test_that("test secsse_sim", {
root_state_weight <- "proper_weights"
sampling_fraction <- c(1, 1, 1)

testthat::expect_message(
testthat::expect_warning(
model_R <- secsse::cla_secsse_ml(
phylotree,
Expand All @@ -46,7 +45,7 @@ test_that("test secsse_sim", {
optimmethod,
num_cycles = 1,
verbose = FALSE)
))
)

qs <- model_R$MLpars[[3]]
diag(qs) <- 0
Expand Down

0 comments on commit 8479bf7

Please sign in to comment.