diff --git a/man/create_layer.Rd b/man/create_layer.Rd index 7917e8854..81f5e33b0 100644 --- a/man/create_layer.Rd +++ b/man/create_layer.Rd @@ -9,9 +9,9 @@ create_layer(name = NULL, open = rlang::is_interactive()) \arguments{ \item{name}{Either a name without extension, or \code{NULL} to create the paired file based on currently open file in the script editor. If -the R file is open, \code{use_test()} will create/open the corresponding +the \verb{R/} file is open, \code{use_test()} will create/open the corresponding test file; if the test file is open, \code{use_r()} will create/open the -corresponding R file.} +corresponding \verb{R/} file.} \item{open}{Whether to open the file for interactive editing.} } diff --git a/tests/testthat/test-assign_arg_list.R b/tests/testthat/test-assign_arg_list.R new file mode 100644 index 000000000..7cd69dfa9 --- /dev/null +++ b/tests/testthat/test-assign_arg_list.R @@ -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) +}) diff --git a/tests/testthat/test-df_mat_mul.R b/tests/testthat/test-df_mat_mul.R new file mode 100644 index 000000000..fe370bd5f --- /dev/null +++ b/tests/testthat/test-df_mat_mul.R @@ -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(df,20)) + expect_error(df_mat_mul(30,mat)) +}) + +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))) +}) diff --git a/tests/testthat/test-grab_names.R b/tests/testthat/test-grab_names.R new file mode 100644 index 000000000..2e7954ab3 --- /dev/null +++ b/tests/testthat/test-grab_names.R @@ -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")) + ) +})