Skip to content

Commit

Permalink
unit tests for tidymodels/parsnip#353
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Jul 30, 2020
1 parent bc5e0ca commit 9b2cffc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.DS_Store
.Rproj.user
.Rhistory
16 changes: 16 additions & 0 deletions tests/testthat/test-encodings-glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ test_that('parsnip models with formula interface', {

expect_true(sum(grepl("(Intercept)", parsnip_form_names)) == 1)
expect_true(sum(grepl("^Alley", parsnip_form_names)) == 2)

expect_error(
predict(parsnip_form_fit, ames %>% select(Year_Built, Alley)),
regex = NA
)

})

test_that('parsnip models with xy interface', {
Expand All @@ -41,6 +47,11 @@ test_that('parsnip models with xy interface', {
parsnip_xy_names <- tidy(parsnip_xy_fit)$term

expect_true(sum(grepl("(Intercept)", parsnip_xy_names)) == 1)

expect_error(
predict(parsnip_xy_fit, ames %>% select(Year_Built, Longitude)),
regex = NA
)
})

## -----------------------------------------------------------------------------
Expand All @@ -65,6 +76,11 @@ test_that('workflows', {

expect_true(sum(grepl("(Intercept)", parsnip_wflow_names)) == 1)
expect_true(sum(grepl("^Alley", parsnip_wflow_names)) == 2)

expect_error(
predict(parsnip_wflow_fit, ames %>% select(Year_Built, Alley)),
regex = NA
)
})


Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-encodings-randomForest.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ test_that('parsnip models with formula interface', {

parsnip_form_names <- rownames(parsnip_form_fit$fit$importance)
expect_true(sum(grepl("Location", parsnip_form_names)) == 1)

expect_error(
predict(parsnip_form_fit, scat),
regex = NA
)
})

test_that('parsnip models with xy interface', {
Expand All @@ -34,6 +39,11 @@ test_that('parsnip models with xy interface', {
parsnip_xy_names <- rownames(parsnip_xy_fit$fit$importance)
expect_true(sum(grepl("Location", parsnip_xy_names)) == 1)

expect_error(
predict(parsnip_xy_fit, scat[, -1]),
regex = NA
)

})

## -----------------------------------------------------------------------------
Expand All @@ -59,6 +69,10 @@ test_that('workflows', {

expect_true(sum(grepl("Location", parsnip_wflow_names)) == 1)

expect_error(
predict(parsnip_wflow_fit, scat[, -1]),
regex = NA
)
})


Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-encodings-ranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ test_that('parsnip models with formula interface', {

parsnip_form_names <- names(parsnip_form_fit$fit$variable.importance)
expect_true(sum(grepl("Location", parsnip_form_names)) == 1)

expect_error(
predict(parsnip_form_fit, scat),
regex = NA
)
})

test_that('parsnip models with xy interface', {
Expand All @@ -34,6 +39,10 @@ test_that('parsnip models with xy interface', {
parsnip_xy_names <- names(parsnip_xy_fit$fit$variable.importance)
expect_true(sum(grepl("Location", parsnip_xy_names)) == 1)

expect_error(
predict(parsnip_xy_fit, scat[, -1]),
regex = NA
)
})

## -----------------------------------------------------------------------------
Expand All @@ -59,6 +68,10 @@ test_that('workflows', {

expect_true(sum(grepl("Location", parsnip_wflow_names)) == 1)

expect_error(
predict(parsnip_wflow_fit, scat[, -1]),
regex = NA
)
})


Expand Down

0 comments on commit 9b2cffc

Please sign in to comment.