Skip to content

Commit 71425ee

Browse files
authored
Merge pull request #1 from kenmawer/km-test-df_mat_mul
Merge with my main
2 parents 5beb5e8 + 4d0e44a commit 71425ee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/testthat/test-df_mat_mul.R

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
df <- data.frame(matrix(1:100, ncol = 5))
2+
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", {
5+
expect_error(df_mat_mul(30,mat))
6+
expect_error(df_mat_mul(df,20))
7+
})
8+
9+
test_that("Incompatible matrix multipication cannot happen", {
10+
expect_error(df_mat_mul(df, mat, "z", dplyr::num_range("X", 1:3)))
11+
})
12+
13+
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)
19+
})

0 commit comments

Comments
 (0)