Skip to content

Commit

Permalink
Adjusted unit test expectations (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed May 23, 2024
1 parent bcf9e97 commit 6907ad8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-MADMMplasso.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fit_R <- suppressWarnings(
test_that("C++ and R versions basically output the same thing", {
expect_named(fit_C$beta, names(fit_R$beta))
tl <- 1e1
expect_equal(fit_C$beta0[, , 1], fit_R$beta0[[1]][1, ], tolerance = tl)
expect_equal(fit_C$beta0[, , 1], fit_R$beta0[[1]], tolerance = tl)
expect_equal(as.vector(fit_C$beta[, , 1]), as.vector(fit_R$beta[[1]]), tolerance = tl)
expect_equal(as.vector(fit_C$BETA_hat[, , 1]), as.vector(fit_R$BETA_hat[[1]]), tolerance = tl)
expect_equal(fit_C$theta0[, , 1], fit_R$theta0[[1]], tolerance = tl)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-admm_MADMMplasso_cpp.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ beta_hat <- my_values$beta_hat
y_hat <- my_values$y_hat

test_that("final objects have correct dimensions", {
expect_identical(dim(beta0), c(1L, 6L))
expect_identical(length(beta0), 6L)
expect_identical(dim(theta0), c(4L, 6L))
expect_identical(dim(beta), c(50L, 6L))
expect_identical(dim(theta), c(50L, 4L, 6L))
Expand Down Expand Up @@ -205,7 +205,7 @@ test_that("C++ function output structure", {

test_that("Values are the same", {
tl <- 1e-1
expect_equal(my_values$beta0, t(my_values_cpp$beta0), tolerance = tl)
expect_equal(my_values$beta0, my_values_cpp$beta0[, 1], tolerance = tl)
expect_equal(my_values$theta0, my_values_cpp$theta0, tolerance = tl)
expect_equal(my_values$beta, my_values_cpp$beta, tolerance = tl)
expect_equal(my_values$theta, my_values_cpp$theta, tolerance = tl)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test_that("reg() produces the correct output", {
for (rp in seq_len(reps)) {
r <- matrix(rnorm(n_obs[rp] * n_vars[rp]), n_obs[rp], n_vars[rp])
z <- as.matrix(sample(0:1, n_obs[rp], replace = TRUE))
expect_identical(reg(r, z), reg_R(r, z), tolerance = 1e-10)
expect_identical(reg(r, z)[1, ], reg_R(r, z)[[1]][1, ], tolerance = 1e-10)
expect_identical(reg(r, z)[2, ], reg_R(r, z)[[2]][1, ], tolerance = 1e-10)
}
})

0 comments on commit 6907ad8

Please sign in to comment.