Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc cleanup #52

Merged
merged 13 commits into from
Feb 1, 2024
Prev Previous commit
Next Next commit
test lints
olivroy committed Jan 31, 2024
commit a425b526127a6ccca8833dcfc2744e9c276ccff1
2 changes: 1 addition & 1 deletion tests/testthat/test-audit.R
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ data_grim <- grim_map(pigs1)
audit_grim <- audit(data_grim)

test_that("`audit()` summarizes GRIM tests accurately", {
expect_true(is.data.frame(audit_grim))
expect_s3_class(audit_grim, "data.frame")
expect_equal(as.numeric(audit_grim$all_cases - audit_grim$incons_cases),
length(data_grim$consistency[data_grim$consistency]))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-debit-map.R
Original file line number Diff line number Diff line change
@@ -5,11 +5,11 @@ df1_tested <- debit_map(df1)


test_that("the output is a tibble", {
df1_tested %>% tibble::is_tibble() %>% expect_true()
df1_tested %>% expect_s3_class("tbl_df")
})

test_that("values are correctly tested for DEBIT-consistency", {
df1_tested$consistency[df1_tested$consistency] %>% length() %>% expect_equal(6)
df1_tested$consistency[df1_tested$consistency] %>% expect_length(6L)
})

test_that("`show_rec` controls the number of columns", {
2 changes: 1 addition & 1 deletion tests/testthat/test-debit-plot.R
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ plot1 <- pigs3 %>%


test_that("`debit_plot()` returns a ggplot object", {
plot1 %>% ggplot2::is.ggplot() %>% expect_true()
plot1 %>% expect_s3_class("ggplot")
})

test_that("The S3 inheritance check works correctly", {
5 changes: 2 additions & 3 deletions tests/testthat/test-disperse.R
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@
df1 <- disperse(n = 20, dispersion = 0:5)

test_that("The function returns a tibble", {
df1 %>% tibble::is_tibble() %>% expect_true()
df1 %>% expect_s3_class("tbl_df")
})

test_that("It has the right dimensions", {
df1 %>% nrow() %>% expect_equal(12)
df1 %>% ncol() %>% expect_equal(2)
df1 %>% dim() %>% expect_equal(c(12, 2))
})

test_that("It starts with the right values", {
8 changes: 4 additions & 4 deletions tests/testthat/test-grim-granularity.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


test_that("`grim_granularity()` returns a numeric value", {
grim_granularity(20, 1) %>% is.numeric() %>% expect_true()
grim_granularity(20, 2) %>% is.numeric() %>% expect_true()
grim_granularity(25, 1) %>% is.numeric() %>% expect_true()
grim_granularity(25, 2) %>% is.numeric() %>% expect_true()
grim_granularity(20, 1) %>% expect_type("double")
grim_granularity(20, 2) %>% expect_type("double")
grim_granularity(25, 1) %>% expect_type("double")
grim_granularity(25, 2) %>% expect_type("double")
})


10 changes: 5 additions & 5 deletions tests/testthat/test-grim-map-total-n.R
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ df2_rows_1_3_expected <- tibble::tibble(
),
case = rep(rep(1:2, 2), each = 12L),
dir = factor(rep(c("forth", "back"), each = 24L), levels = c("forth", "back")),
) |>
) %>%
structure(
class = c(
"scr_map_total_n", "scr_grim_map", "scr_rounding_up_or_down", "tbl_df", "tbl",
@@ -67,8 +67,8 @@ df2_tested <- df2 %>% grim_map_total_n(dispersion = 0:5)


test_that("The output is a tibble", {
df1_tested %>% tibble::is_tibble() %>% expect_true()
df2_tested %>% tibble::is_tibble() %>% expect_true()
expect_s3_class(df1_tested, "tbl_df")
expect_s3_class(df2_tested, "tbl_df")
})

test_that("It has correct dimensions", {
@@ -88,8 +88,8 @@ colnames_exp <- c(


test_that("It has correct column names", {
df1_tested %>% colnames() %>% expect_equal(colnames_exp)
df2_tested %>% colnames() %>% expect_equal(colnames_exp)
df1_tested %>% expect_named(colnames_exp)
df2_tested %>% expect_named(colnames_exp)
})


24 changes: 11 additions & 13 deletions tests/testthat/test-grim-map.R
Original file line number Diff line number Diff line change
@@ -17,26 +17,24 @@ df1_grim <- grim_map(df1)


test_that("A tibble is returned", {
df1_grim %>% is.data.frame() %>% expect_true()
df1_grim %>% inherits("tbl_df") %>% expect_true()
df1_grim %>% inherits("tbl") %>% expect_true()
expect_s3_class(df1_grim, c("tbl_df", "tbl", "data.frame"))
})



test_that("It has the correct function-general class", {
expect_true(inherits(df1_grim, "scr_grim_map"))
expect_s3_class(df1_grim, "scr_grim_map")
})

test_that("It has the correct rounding-specific class", {
df1_grim_up_or_down %>% inherits("scr_rounding_up_or_down") %>% expect_true()
df1_grim_up %>% inherits("scr_rounding_up") %>% expect_true()
df1_grim_down %>% inherits("scr_rounding_down") %>% expect_true()
df1_grim_ceiling_or_floor %>% inherits("scr_rounding_ceiling_or_floor") %>% expect_true()
df1_grim_ceiling %>% inherits("scr_rounding_ceiling") %>% expect_true()
df1_grim_floor %>% inherits("scr_rounding_floor") %>% expect_true()
df1_grim_trunc %>% inherits("scr_rounding_trunc") %>% expect_true()
df1_grim_anti_trunc %>% inherits("scr_rounding_anti_trunc") %>% expect_true()
df1_grim_up_or_down %>% expect_s3_class("scr_rounding_up_or_down")
df1_grim_up %>% expect_s3_class("scr_rounding_up")
df1_grim_down %>% expect_s3_class("scr_rounding_down")
df1_grim_ceiling_or_floor %>% expect_s3_class("scr_rounding_ceiling_or_floor")
df1_grim_ceiling %>% expect_s3_class("scr_rounding_ceiling")
df1_grim_floor %>% expect_s3_class("scr_rounding_floor")
df1_grim_trunc %>% expect_s3_class("scr_rounding_trunc")
df1_grim_anti_trunc %>% expect_s3_class("scr_rounding_anti_trunc")
})


@@ -159,7 +157,7 @@ df7 <- df1 %>%


test_that("`show_prob` adds a `prob` column", {
"prob" %in% colnames(df7) %>% expect_true()
expect_contains(colnames(df7), "prob")
})


2 changes: 1 addition & 1 deletion tests/testthat/test-grim-plot.R
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ plot <- pigs1 %>%
grim_plot()

test_that("`grim_plot()` returns a ggplot object", {
plot %>% inherits("ggplot") %>% expect_true()
plot %>% expect_s3_class("ggplot")
})
12 changes: 4 additions & 8 deletions tests/testthat/test-grim.R
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ test_that("A numeric argument for `x` leads to failure", {


test_that("Return values are Boolean", {
expect_true(is.logical(grim("5.19", 28)))
expect_true(is.logical(grim("0.00", 100)))
expect_type(grim("5.19", 28), "logical")
expect_type(grim("0.00", 100), "logical")
})


@@ -78,14 +78,10 @@ test_that("Correct values are returned (`percent` argument)", {

vec <- seq_endpoint(5, 5.99)

vec_all_right_name <- vec %>%
grim(28) %>%
hasName(vec) %>%
all()


test_that("The `x` vector reappears as the names of the return values", {
vec_all_right_name %>% expect_true()
expect_named(grim(vec, 28), vec)
})


@@ -106,7 +102,7 @@ x <- rnorm(x_length, 50, 20) %>%


test_that("There are as many outputs as inputs", {
grim(x, 50) %>% length() %>% expect_equal(x_length)
grim(x, 50) %>% expect_length(x_length)
})


10 changes: 4 additions & 6 deletions tests/testthat/test-method-grim-map.R
Original file line number Diff line number Diff line change
@@ -12,16 +12,14 @@ audit_pigs2 <- pigs2 %>%


test_that("The output is a tibble", {
audit_pigs1 %>% tibble::is_tibble() %>% expect_true()
audit_pigs2 %>% tibble::is_tibble() %>% expect_true()
audit_pigs1 %>% expect_s3_class("tbl_df")
audit_pigs2 %>% expect_s3_class("tbl_df")
})


test_that("The output has correct dimensions", {
audit_pigs1 %>% ncol() %>% expect_equal(7)
audit_pigs1 %>% nrow() %>% expect_equal(1)
audit_pigs2 %>% ncol() %>% expect_equal(7)
audit_pigs2 %>% nrow() %>% expect_equal(1)
audit_pigs1 %>% dim() %>% expect_equal(c(1, 7))
audit_pigs2 %>% dim() %>% expect_equal(c(1, 7))
})


2 changes: 1 addition & 1 deletion tests/testthat/test-method-grim-sequence.R
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ ranking <- seq_distance_df("5.37", n = 40) %>%


test_that("The function returns a tibble", {
ranking %>% tibble::is_tibble() %>% expect_true()
ranking %>% expect_s3_class("tbl_df")
})

test_that("Dimensions are correct", {
28 changes: 8 additions & 20 deletions tests/testthat/test-restore-zeros.R
Original file line number Diff line number Diff line change
@@ -41,8 +41,7 @@ test_that("The `*_df()` variant produces correct results", {
dplyr::select(5) %>%
restore_zeros_df() %>%
dplyr::pull(1) %>%
is.factor() %>%
expect_true()
expect_s3_class("factor")
})


@@ -53,24 +52,13 @@ test_that("the `check_decimals` argument works correctly", {
dplyr::pull(1) %>%
expect_type("double")

iris %>%
dplyr::mutate(Sepal.Length = trunc(Sepal.Length)) %>%
restore_zeros_df(check_decimals = FALSE) %>%
dplyr::pull(1) %>%
expect_warning()

iris %>%
dplyr::mutate(Sepal.Length = trunc(Sepal.Length)) %>%
restore_zeros_df(check_decimals = FALSE) %>%
dplyr::pull(1) %>%
expect_warning()

iris %>%
dplyr::mutate(Sepal.Length = trunc(Sepal.Length)) %>%
restore_zeros_df(check_decimals = FALSE) %>%
dplyr::pull(1) %>%
suppressWarnings() %>%
expect_type("character")
expect_warning(
out <- iris %>%
dplyr::mutate(Sepal.Length = trunc(Sepal.Length)) %>%
restore_zeros_df(check_decimals = FALSE) %>%
dplyr::pull(1)
)
expect_type(out, "character")
})


12 changes: 6 additions & 6 deletions tests/testthat/test-split-by-parens.R
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@ pigs_tested <- split_by_parens(pigs)


test_that("The output is a tibble", {
pigs_tested %>% tibble::is_tibble() %>% expect_true()
expect_s3_class(pigs_tested, "tbl_df")
})


colnames_expected <- c("drone_x", "drone_sd", "selfpilot_x", "selfpilot_sd")

test_that("It has correct column names", {
pigs_tested %>% colnames() %>% expect_equal(colnames_expected)
expect_named(pigs_tested, colnames_expected)
})


@@ -89,13 +89,13 @@ test_that("using the dots, `...`, is an error", {
pigs_wider <- pigs %>% dplyr::mutate(letters = letters[1:4])

test_that("non-`sep` columns are handled correctly with `check_sep = TRUE` (the default)", {
pigs_wider %>% split_by_parens() %>% expect_warning()
pigs_wider %>% split_by_parens() %>% suppressWarnings() %>% ncol() %>% expect_equal(5L)
expect_warning(out <- split_by_parens(pigs_wider))
expect_equal(ncol(out), 5L)
})

test_that("non-`sep` columns are handled correctly with `check_sep = FALSE", {
pigs_wider %>% split_by_parens(check_sep = FALSE) %>% expect_warning()
pigs_wider %>% split_by_parens(check_sep = FALSE) %>% suppressWarnings() %>% ncol() %>% expect_equal(6L)
expect_warning(out <- split_by_parens(pigs_wider, check_sep = FALSE))
expect_equal(ncol(out), 6L)
})


6 changes: 3 additions & 3 deletions tests/testthat/test-unround.R
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@ df1 <- unround(c(3.6, "5.20", 5.174)) %>%


test_that("The output is a tibble", {
df1 %>% tibble::is_tibble() %>% expect_true()

df1 %>% expect_s3_class("tbl_df")
})

test_that("It has correct dimensions", {
df1 %>% nrow() %>% expect_equal(3)
df1 %>% ncol() %>% expect_equal(7)
df1 %>% dim() %>% expect_equal(c(3, 7))
})