Skip to content

Updated tests to work for good. #80

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

Merged
merged 5 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions man/create_layer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/new_epi_recipe_blueprint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test-assign_arg_list.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("First argument must be a list",{
expect_error(assign_arg_list(c(1,2,3)))
})
test_that("All arguments should be named",{
expect_error(assign_arg_list(list(1,2)))
})
test_that("assign_arg_list works as intended",{
assign_arg_list(list(a="dog",b=2))
expect_identical(a,"dog")
expect_identical(b,2)
})
41 changes: 41 additions & 0 deletions tests/testthat/test-df_mat_mul.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
df <- data.frame(matrix(1:100, ncol = 5))
mat <- matrix(1:4, ncol = 2)

test_that("First input must be a data frame and second input must be a matrix",
{
expect_error(df_mat_mul(30,mat))
expect_error(df_mat_mul(df,20))
})

test_that("Argument name is a character" ,{
expect_error(df_mat_mul(df, mat, 100))
})

test_that("The length of names does not differ from the length of the number
of outputs" ,{
expect_error(df_mat_mul(df, mat, c("a","b","c"), 2:3))
})

test_that("The number of columns of the first data frame cannot differ from the
number of rows of the second matrix, hence preventing incompatible
matrix multiplication", {
expect_error(df_mat_mul(df, mat, "z", 1:3))
})

X <- df[c(1,4,5)]
Z <- as.data.frame(as.matrix(df[2:3]) %*% mat)
colnames(Z) <- c("z1","z2")
output <- cbind(X,Z)

test_that("Names are being handled properly", {
expect_identical(df_mat_mul(df, mat, "z", 2:3),output)
expect_identical(df_mat_mul(df, mat, c("z1","z2"), 2:3),output)
})

test_that("Other tidyselect functionalities are working", {
mult <- df_mat_mul(df, mat, "z", dplyr::num_range("X", 2:3))
expect_identical(mult,output)
expect_identical(df_mat_mul(df, mat, "z", 2, 3),output)
# Mismatched names should not work:
expect_error(df_mat_mul(df, mat, "z", dplyr::num_range("Y", 2:3)))
})
7 changes: 7 additions & 0 deletions tests/testthat/test-grab_names.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
df <- data.frame(b=1,c=2,ca=3,cat=4)

test_that("Names are grabbed properly", {
expect_identical(grab_names(df,dplyr::starts_with("ca")),
subset(names(df),startsWith(names(df), "ca"))
)
})