Skip to content

Commit c4948a5

Browse files
authored
Merge pull request #29 from kenmawer/km-pr_34_rectify_tests
Km pr 34 rectify tests
2 parents 3c0bd3c + efc4e06 commit c4948a5

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

tests/testthat/test-assign_arg_list.R

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ test_that("First argument must be a list",{
44
test_that("All arguments should be named",{
55
expect_error(assign_arg_list(list(1,2)))
66
})
7+
test_that("assign_arg_list works as intended",{
8+
assign_arg_list(list(a="dog",b=2))
9+
expect_identical(a,"dog")
10+
expect_identical(b,2)
11+
})

tests/testthat/test-df_mat_mul.R

+33-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
df <- data.frame(matrix(1:100, ncol = 5))
22
mat <- matrix(1:4, ncol = 2)
3-
df_mat_mul(df, mat, "z", dplyr::num_range("X", 2:3))
4-
test_that("df_mat_mul checks inputs", {
3+
4+
test_that("First input must be a data frame and second input must be a matrix",
5+
{
56
expect_error(df_mat_mul(30,mat))
67
expect_error(df_mat_mul(df,20))
78
})
89

9-
test_that("Incompatible matrix multipication cannot happen", {
10-
expect_error(df_mat_mul(df, mat, "z", dplyr::num_range("X", 1:3)))
10+
test_that("Argument name is a character" ,{
11+
expect_error(df_mat_mul(df, mat, 100))
12+
})
13+
14+
test_that("The length of names does not differ from the length of the number
15+
of outputs" ,{
16+
expect_error(df_mat_mul(df, mat, c("a","b","c"),
17+
dplyr::num_range("X", 2:3)))
1118
})
1219

20+
test_that("The number of columns of the first data frame cannot differ from the
21+
number of rows of the second matrix, hence preventing incompatible
22+
matrix multiplication", {
23+
expect_error(df_mat_mul(df, mat, "z", 1:3))
24+
})
25+
26+
X <- df[c(1,4,5)]
27+
Z <- as.data.frame(as.matrix(df[2:3]) %*% mat)
28+
colnames(Z) <- c("z1","z2")
29+
output <- cbind(X,Z)
30+
1331
test_that("Matrix multiplication is being handled as expected", {
14-
X <- df[c(1,4,5)]
15-
Z <- as.data.frame(as.matrix(df[2:3]) %*% mat)
16-
colnames(Z) <- c("z1","z2")
17-
output <- cbind(X,Z)
18-
expect_identical(df_mat_mul(df,mat, "z", dplyr::num_range("X", 2:3)),output)
32+
expect_identical(df_mat_mul(df, mat, "z", 2:3),output)
33+
})
34+
35+
test_that("Names are used from the out_names field", {
36+
expect_identical(df_mat_mul(df, mat, c("z1","z2"), 2:3),output)
37+
})
38+
39+
test_that("Other tidyselect functionalities are working", {
40+
mult <- df_mat_mul(df, mat, "z", dplyr::num_range("X", 2:3))
41+
expect_identical(mult,output)
42+
expect_identical(df_mat_mul(df, mat, "z", 2, 3),output)
1943
})

0 commit comments

Comments
 (0)