Skip to content

Commit 0dbfc2e

Browse files
authored
Merge pull request #30 from kenmawer/km-pr_34_rectify_tests
Km pr 34 rectify tests
2 parents c4948a5 + d73d9e2 commit 0dbfc2e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

tests/testthat/test-df_mat_mul.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ test_that("Argument name is a character" ,{
1313

1414
test_that("The length of names does not differ from the length of the number
1515
of outputs" ,{
16-
expect_error(df_mat_mul(df, mat, c("a","b","c"),
17-
dplyr::num_range("X", 2:3)))
16+
expect_error(df_mat_mul(df, mat, c("a","b","c"), 2:3))
1817
})
1918

2019
test_that("The number of columns of the first data frame cannot differ from the
@@ -28,16 +27,15 @@ Z <- as.data.frame(as.matrix(df[2:3]) %*% mat)
2827
colnames(Z) <- c("z1","z2")
2928
output <- cbind(X,Z)
3029

31-
test_that("Matrix multiplication is being handled as expected", {
30+
test_that("Names are being handled properly", {
3231
expect_identical(df_mat_mul(df, mat, "z", 2:3),output)
33-
})
34-
35-
test_that("Names are used from the out_names field", {
3632
expect_identical(df_mat_mul(df, mat, c("z1","z2"), 2:3),output)
3733
})
3834

3935
test_that("Other tidyselect functionalities are working", {
4036
mult <- df_mat_mul(df, mat, "z", dplyr::num_range("X", 2:3))
4137
expect_identical(mult,output)
4238
expect_identical(df_mat_mul(df, mat, "z", 2, 3),output)
39+
# Mismatched names should not work:
40+
expect_error(df_mat_mul(df, mat, "z", dplyr::num_range("Y", 2:3)))
4341
})

tests/testthat/test-step_epi_naomit.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ z2 <- r %>%
2121
step_naomit(all_predictors()) %>%
2222
step_naomit(all_outcomes(), skip = TRUE)
2323

24-
# Test
24+
# Checks the behaviour of a step function, omitting the quosure and id that
25+
# differ from one another, even with identical behaviour
26+
behav <- function(recipe,step_num) recipe$steps[[step_num]][-1][-5]
27+
# Checks the class type of an object
28+
step_class <- function(recipe,step_num) class(recipe$steps[step_num])
29+
2530
test_that("Check that both functions behave the same way", {
26-
expect_identical(z1$steps[[3]][-1][-5],z2$steps[[3]][-1][-5])
27-
expect_identical(z1$steps[[4]][-1][-5],z2$steps[[4]][-1][-5])
28-
expect_identical(class(z1$steps[[3]]),class(z2$steps[[3]]))
29-
expect_identical(class(z1$steps[[4]]),class(z2$steps[[4]]))
31+
expect_identical(behav(z1,3),behav(z2,3))
32+
expect_identical(behav(z1,4),behav(z2,4))
33+
expect_identical(step_class(z1,3),step_class(z2,3))
34+
expect_identical(step_class(z1,4),step_class(z2,4))
3035
})

0 commit comments

Comments
 (0)