Skip to content

Commit

Permalink
udpate tests (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Aug 29, 2024
1 parent 5904191 commit 8671440
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
10 changes: 6 additions & 4 deletions tests/testthat/test-matrix_form.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
test_that("matrix_form works with and without indentation", {
require("dplyr", quietly = TRUE)

skip_if_not_installed("dplyr")

iris_output <- dplyr::summarize(dplyr::group_by(iris, Species),
"all obs" = round(mean(Petal.Length), 2)
)
iris_output <- dplyr::mutate(iris_output, "Petal.Length" = "Mean")
iris_output <- iris %>%
group_by(Species) %>%
summarize("all obs" = round(mean(Petal.Length), 2)) %>%
mutate("Petal.Length" = "Mean")

mf <- basic_matrix_form(iris_output,
indent_rownames = TRUE,
Expand Down
47 changes: 22 additions & 25 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
test_that("toString works with and without indentation", {
require("dplyr", quietly = TRUE)

skip_if_not_installed("dplyr")

set.seed(1)
iris <-
dplyr::mutate(iris, my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE))
iris_output <-
dplyr::summarize(dplyr::group_by(iris, Species, my_cols),
"mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop"
)
iris_output_df <- as.data.frame(iris_output)
iris_output_df <- reshape(
iris_output_df,
timevar = "my_cols",
idvar = "Species",
direction = "wide",
v.names = "mean_petal_length"
)
# identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>%
iris_output_df <- dplyr::rename(
iris_output_df,
A = `mean_petal_length.A`,
B = `mean_petal_length.B`,
C = `mean_petal_length.C`
)

iris_output_df <- dplyr::mutate(iris_output_df, "Petal.Length" = "Mean")
iris_output <- iris %>%
mutate(my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE)) %>%
group_by(Species, my_cols) %>%
summarize("mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop") %>%
as.data.frame() %>%
reshape(
timevar = "my_cols",
idvar = "Species",
direction = "wide",
v.names = "mean_petal_length"
) %>%
# identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>%
rename(
A = `mean_petal_length.A`,
B = `mean_petal_length.B`,
C = `mean_petal_length.C`
) %>%
mutate("Petal.Length" = "Mean")

mf <- basic_matrix_form(iris_output_df,
mf <- basic_matrix_form(iris_output,
indent_rownames = TRUE,
split_labels = "Species", data_labels = "Petal.Length"
)
mf_no_indent <- basic_matrix_form(iris_output_df,
mf_no_indent <- basic_matrix_form(iris_output,
indent_rownames = FALSE,
split_labels = "Species", data_labels = "Petal.Length"
)
Expand Down

0 comments on commit 8671440

Please sign in to comment.