Skip to content

Commit

Permalink
Update most tests to 3rd edition of testthat
Browse files Browse the repository at this point in the history
  • Loading branch information
asardaes committed Dec 31, 2024
1 parent 0330eb8 commit fcfada2
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 42 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Language: en-US
Encoding: UTF-8
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row sums")

test_that("row_sums can handle errors and edge cases appropriately.", {
suppressWarnings(
expect_error(regexp = "not support", row_sums(char_mat, output_mode = "integer"))
Expand Down Expand Up @@ -249,6 +247,8 @@ test_that("row_sums for complex matrices works.", {
})

test_that("row_sums for complex matrices with NAs works.", {
local_edition(2)

expected <- rowSums(cplx_na_mat, na.rm = TRUE)
ans <- row_sums(cplx_na_mat)
expect_equal(ans, expected)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row NAs")

test_that("row_nas for integer matrices works.", {
expected <- apply(int_na_mat, 1L, function(x) { all(is.na(x)) })
ans <- row_nas(int_na_mat, "all")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row Infs")

test_that("row_infs works as expected.", {
dbl_cols <- sapply(df, is.double)
cplx_cols <- sapply(df, is.complex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row Finites")

test_that("row_finites works as expected.", {
dbl_cols <- sapply(df, is.double)
cplx_cols <- sapply(df, is.complex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row Compare")

test_that("row_compare throws if an element of values has length != 0", {
expect_error(row_compare(dbl_mat, values = list(1:2)), "length equal to 1")
expect_error(row_compare(df, values = list(1:2)), "length equal to 1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
context(" Row arith")
# NOTE: row_sums came first, so its tests check most cases

test_that("row_arith correctly infers output mode.", {
Expand Down Expand Up @@ -28,6 +27,8 @@ test_that("row_arith correctly infers output mode.", {
})

test_that("row_arith behaves as expected for data frames.", {
local_edition(2)

df <- df[, sapply(df, typeof) != "character"]

considered_cols <- list(
Expand Down Expand Up @@ -67,6 +68,8 @@ test_that("row_arith behaves as expected for data frames.", {
})

test_that("row_arith can accumulate.", {
local_edition(2)

rows <- 1001:1500

expect_error(row_arith(int_mat, cumulative = TRUE, output_class = "vector"), "cumulative")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row In")

test_that("row_in handles basic input errors.", {
expect_error(row_in(matrix()), "empty")
expect_error(row_in(data.frame()), "empty")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row Duplicated")

test_that("row_duplicated throws for invalid output class.", {
expect_error(row_duplicated(int_mat, output_class = "vector"), "output class")
expect_error(row_duplicated(df, output_class = "vector"), "output class")
Expand Down Expand Up @@ -39,7 +37,7 @@ test_that("row_duplicated's internal promotions work as expected.", {

expected <- as.data.frame(t(apply(df[, cols], 1L, duplicated)))
ans <- row_duplicated(df, cols = cols)
expect_equal(ans, expected, check.attributes = FALSE)
expect_equal(ans, expected, ignore_attr = TRUE)
}
}
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row means")

test_that("row_means can handle errors and edge cases appropriately.", {
suppressWarnings(
expect_error(regexp = "not support", row_means(char_mat, output_mode = "integer"))
Expand Down Expand Up @@ -250,6 +248,8 @@ test_that("row_means for complex matrices works.", {
})

test_that("row_means for complex matrices with NAs works.", {
local_edition(2)

expected <- rowMeans(cplx_na_mat, na.rm = TRUE)
ans <- row_means(cplx_na_mat)
expect_equal(ans, expected)
Expand All @@ -260,6 +260,8 @@ test_that("row_means for complex matrices with NAs works.", {
})

test_that("row_means for complex matrices with column subset works.", {
local_edition(2)

expected <- rowMeans(cplx_mat[, -2L])
ans <- row_means(cplx_mat, cols = c(1, 3))
expect_equal(ans, expected)
Expand Down Expand Up @@ -330,6 +332,8 @@ test_that("row_means for data frames works.", {
})

test_that("row_means can accumulate.", {
local_edition(2)

cummeans <- function(x, na.rm = FALSE) {
if (!na.rm) return(cumsum(x) / seq_along(x))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row extrema")

test_that("Error is thrown if complex numbers are involved.", {
expect_error(wiserow:::row_extrema_matrix(cplx_mat), "typeof")
expect_error(wiserow:::row_extrema_df(df), "complex")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row max")

test_that("row_max works for matrices.", {
matrices <- list(bool_na_mat, int_na_mat, dbl_na_mat, char_na_mat)
na_actions <- wiserow:::.supported_na_actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Row min")

test_that("row_min works for matrices.", {
matrices <- list(bool_na_mat, int_na_mat, dbl_na_mat, char_na_mat)
na_actions <- wiserow:::.supported_na_actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context(" Miscellaneous")

# some of these use row_sums as gateway because it was the first R function

test_that("tidyselect support works.", {
Expand Down
16 changes: 0 additions & 16 deletions tests/testthat/test-10-unit.R

This file was deleted.

0 comments on commit fcfada2

Please sign in to comment.