Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Sep 17, 2024
1 parent a592dd2 commit 0c19ade
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/coerce.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
sparsevctrs: Sparse vector materialized
sparsevctrs: Sparse vector materialized

# coerce_to_sparse_matrix() can pass through error call

Code
tmp_fun(1)
Condition
Error in `tmp_fun()`:
! `x` must be a <data.frame>, not a number.

---

Code
tmp_fun(1)
Condition
Error in `tmp_fun()`:
! `x` must be a <sparseMatrix>, not a number.

# coerce_to_sparse_data_frame() errors with no column names

Code
Expand All @@ -55,6 +71,14 @@
Error in `coerce_to_sparse_data_frame()`:
! `x` must be a <sparseMatrix>, not an integer vector.

# coerce_to_sparse_data_frame() can pass through error call

Code
tmp_fun(1)
Condition
Error in `tmp_fun()`:
! `x` must be a <sparseMatrix>, not a number.

# coerce_to_sparse_tibble() errors with no column names

Code
Expand Down
37 changes: 36 additions & 1 deletion tests/testthat/test-coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ test_that("coerce_to_sparse_matrix() materializes non-zero defaulted columns", {
expect_identical(res, exp)
})

test_that("coerce_to_sparse_matrix() can pass through error call", {
tmp_fun <- function(x) {
coerce_to_sparse_matrix(x, call = rlang::caller_env(0))
}

expect_snapshot(
error = TRUE,
tmp_fun(1)
)
})

### coerce_to_sparse_data_frame ------------------------------------------------

test_that("coerce_to_sparse_data_frame() works", {
Expand Down Expand Up @@ -140,6 +151,17 @@ test_that("coerce_to_sparse_data_frame() errors with wrong input", {
)
})

test_that("coerce_to_sparse_data_frame() can pass through error call", {
tmp_fun <- function(x) {
coerce_to_sparse_data_frame(x, call = rlang::caller_env(0))
}

expect_snapshot(
error = TRUE,
tmp_fun(1)
)
})

### coerce_to_sparse_tibble ----------------------------------------------------

test_that("coerce_to_sparse_tibble() works", {
Expand Down Expand Up @@ -204,6 +226,19 @@ test_that("coerce_to_sparse_tibble() errors with wrong input", {
)
})

test_that("coerce_to_sparse_matrix() can pass through error call", {
tmp_fun <- function(x) {
coerce_to_sparse_tibble(x, call = rlang::caller_env(0))
}

expect_snapshot(
error = TRUE,
tmp_fun(1)
)
})

### .sparse_matrix_to_list -----------------------------------------------------

test_that(".sparse_matrix_to_list() handles fully sparse columns (#69)", {
skip_if_not_installed("Matrix")

Expand All @@ -220,4 +255,4 @@ test_that(".sparse_matrix_to_list() handles fully sparse columns (#69)", {
coerce_to_sparse_data_frame(x_mat_sparse),
x_df
)
})
})

0 comments on commit 0c19ade

Please sign in to comment.