Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed May 9, 2024
1 parent 5456d18 commit 0cd6af7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions R/altrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ sparse_double <- function(values, positions, length) {
)
}

if (any(is.nan(values))) {
offenders <- which(is.nan(values))
cli::cli_abort(
c(
x = "{.arg values} must not contain NaN values.",
i = "NaN values at index: {offenders}."
)
)
}

if (is.integer(values)) {
values <- as.double(values)
}
Expand All @@ -64,6 +74,16 @@ sparse_double <- function(values, positions, length) {
)
}

if (any(is.nan(positions))) {
offenders <- which(is.nan(positions))
cli::cli_abort(
c(
x = "{.arg positions} must not contain NaN values.",
i = "NaN values at index: {offenders}."
)
)
}

if (!is.integer(positions)) {
if (any(round(positions) != positions, na.rm = TRUE)) {
offenders <- which(round(positions) != positions)
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/_snaps/altrep.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
Code
sparse_double(NaN, 1, 1)
Condition
Error in `if (any(values == 0)) ...`:
! missing value where TRUE/FALSE needed
Error in `sparse_double()`:
x `values` must not contain NaN values.
i NaN values at index: 1.

---

Expand Down Expand Up @@ -86,8 +87,9 @@
Code
sparse_double(1, NaN, 1)
Condition
Error in `if (len_positions > 0 && max(positions) > length) ...`:
! missing value where TRUE/FALSE needed
Error in `sparse_double()`:
x `positions` must not contain NaN values.
i NaN values at index: 1.

---

Expand Down

0 comments on commit 0cd6af7

Please sign in to comment.