Skip to content

test {cli} changes to check_args() #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/testthat/_snaps/c5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# check_args() works

Code
spec <- C5_rules(trees = c(1, 2, 3)) %>% set_engine("C5.0") %>% set_mode(
"classification")
fit(spec, Class ~ ., data = ad_data$ad_mod)
Condition
Error in `fit()`:
! `tree` must be a whole number or `NULL`, not a double vector.

---

Code
spec <- C5_rules(trees = 0) %>% set_engine("C5.0") %>% set_mode(
"classification")
res <- fit(spec, Class ~ ., data = ad_data$ad_mod)
Condition
Warning:
The number of trees should be `>= 1` and `<= 100`
Truncating to 1.

---

Code
spec <- C5_rules(trees = 1000) %>% set_engine("C5.0") %>% set_mode(
"classification")
res <- fit(spec, Class ~ ., data = ad_data$ad_mod)
Condition
Warning:
The number of trees should be `>= 1` and `<= 100`
Truncating to 100.

---

Code
spec <- C5_rules(min_n = c(1, 2, 3)) %>% set_engine("C5.0") %>% set_mode(
"classification")
fit(spec, Class ~ ., data = ad_data$ad_mod)
Condition
Error in `fit()`:
! `min_n` must be a whole number or `NULL`, not a double vector.

64 changes: 64 additions & 0 deletions tests/testthat/_snaps/cubist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# check_args() works

Code
spec <- cubist_rules(committees = c(1, 2, 3)) %>% set_engine("Cubist") %>%
set_mode("regression")
fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Error in `fit()`:
! `committees` must be a whole number or `NULL`, not a double vector.

---

Code
spec <- cubist_rules(committees = 0) %>% set_engine("Cubist") %>% set_mode(
"regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Warning:
The number of committees should be `>= 1` and `<= 100`.
Truncating to 1.

---

Code
spec <- cubist_rules(committees = 1000) %>% set_engine("Cubist") %>% set_mode(
"regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Warning:
The number of committees should be `>= 1` and `<= 100`.
Truncating to 100.

---

Code
spec <- cubist_rules(neighbors = c(1, 2, 3)) %>% set_engine("Cubist") %>%
set_mode("regression")
fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Error in `fit()`:
! `neighbors` must be a whole number or `NULL`, not a double vector.

---

Code
spec <- cubist_rules(neighbors = -1) %>% set_engine("Cubist") %>% set_mode(
"regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Warning:
The number of neighbors should be `>= 0` and `<= 9`.
Truncating to 0.

---

Code
spec <- cubist_rules(neighbors = 1000) %>% set_engine("Cubist") %>% set_mode(
"regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
Condition
Warning:
The number of neighbors should be `>= 0` and `<= 9`.
Truncating to 9.

45 changes: 45 additions & 0 deletions tests/testthat/test-c5.R
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,48 @@ test_that("tidy method", {
expect_equal(nrow(tidy_2), term_nodes_2)

})

test_that('check_args() works', {
skip_on_cran()
skip_if_not_installed("C50")
skip_if_not_installed("parsnip", "1.2.1.9001")
ad_data <- make_ad_data()

expect_snapshot(
error = TRUE,
{
spec <- C5_rules(trees = c(1, 2, 3)) %>%
set_engine("C5.0") %>%
set_mode("classification")
fit(spec, Class ~ ., data = ad_data$ad_mod)
}
)

expect_snapshot(
{
spec <- C5_rules(trees = 0) %>%
set_engine("C5.0") %>%
set_mode("classification")
res <- fit(spec, Class ~ ., data = ad_data$ad_mod)
}
)

expect_snapshot(
{
spec <- C5_rules(trees = 1000) %>%
set_engine("C5.0") %>%
set_mode("classification")
res <- fit(spec, Class ~ ., data = ad_data$ad_mod)
}
)

expect_snapshot(
error = TRUE,
{
spec <- C5_rules(min_n = c(1, 2, 3)) %>%
set_engine("C5.0") %>%
set_mode("classification")
fit(spec, Class ~ ., data = ad_data$ad_mod)
}
)
})
64 changes: 64 additions & 0 deletions tests/testthat/test-cubist.R
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,67 @@ test_that("mode specific package dependencies", {
list(c("Cubist", "rules"))
)
})


test_that('check_args() works', {
skip_on_cran()
skip_if_not_installed("Cubist")
skip_if_not_installed("parsnip", "1.2.1.9001")
chi_data <- make_chi_data()

expect_snapshot(
error = TRUE,
{
spec <- cubist_rules(committees = c(1, 2, 3)) %>%
set_engine("Cubist") %>%
set_mode("regression")
fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)

expect_snapshot(
{
spec <- cubist_rules(committees = 0) %>%
set_engine("Cubist") %>%
set_mode("regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)

expect_snapshot(
{
spec <- cubist_rules(committees = 1000) %>%
set_engine("Cubist") %>%
set_mode("regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)

expect_snapshot(
error = TRUE,
{
spec <- cubist_rules(neighbors = c(1, 2, 3)) %>%
set_engine("Cubist") %>%
set_mode("regression")
fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)

expect_snapshot(
{
spec <- cubist_rules(neighbors = -1) %>%
set_engine("Cubist") %>%
set_mode("regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)

expect_snapshot(
{
spec <- cubist_rules(neighbors = 1000) %>%
set_engine("Cubist") %>%
set_mode("regression")
res <- fit(spec, ridership ~ ., data = chi_data$chi_mod)
}
)
})
6 changes: 6 additions & 0 deletions tests/testthat/test-rule_fit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("check_args() works", {
skip_if_not_installed("parsnip", "1.2.1.9001")

# Here for completeness, no checking is done
expect_true(TRUE)
})