Skip to content

Commit a41e1c0

Browse files
committed
fix descriptor tests
There are 4 factor levels in hpc_data$class, but 3 in iris$Species, which tripped up a few tests.
1 parent bebc5d5 commit a41e1c0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tests/testthat/test_descriptors.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library(testthat)
22
library(parsnip)
33

44
source(test_path("helper-objects.R"))
5-
hpc <- hpc_data[1:150, c(2:5, 8)]
5+
hpc <- hpc_data[1:150, c(2:5, 8)] %>% as.data.frame()
66

77
# ------------------------------------------------------------------------------
88

@@ -29,7 +29,7 @@ eval_descrs <- function(descrs, not = NULL) {
2929
lapply(descrs, do.call, list())
3030
}
3131

32-
class_tab <- table(hpc_data$class, dnn = NULL)
32+
class_tab <- table(hpc$class, dnn = NULL)
3333

3434
# ------------------------------------------------------------------------------
3535

@@ -86,12 +86,12 @@ context("Testing formula -> xy conversion")
8686

8787
test_that("numeric y and dummy vars", {
8888
expect_equal(
89-
template(5, 4, 150, NA, 1, hpc, hpc[-2], hpc[,"compounds"]),
90-
eval_descrs(get_descr_form(compounds ~ ., data = hpc))
89+
template(6, 4, 150, NA, 1, hpc, hpc[-2], hpc[,"input_fields"]),
90+
eval_descrs(get_descr_form(input_fields ~ ., data = hpc))
9191
)
9292
expect_equal(
93-
template(2, 1, 150, NA, 1, hpc, hpc["class"], hpc[,"compounds"]),
94-
eval_descrs(get_descr_form(compounds ~ class, data = hpc))
93+
template(3, 1, 150, NA, 1, hpc, hpc["class"], hpc[,"input_fields"]),
94+
eval_descrs(get_descr_form(input_fields ~ class, data = hpc))
9595
)
9696
})
9797

@@ -117,8 +117,8 @@ test_that("factor y", {
117117
eval_descrs(get_descr_form(class ~ ., data = hpc))
118118
)
119119
expect_equal(
120-
template(1, 1, 150, class_tab, 0, hpc, hpc["input_fields"], hpc[,"class"]),
121-
eval_descrs(get_descr_form(class ~ input_fields, data = hpc))
120+
template(1, 1, 150, class_tab, 0, hpc, hpc["compounds"], hpc[,"class"]),
121+
eval_descrs(get_descr_form(class ~ compounds, data = hpc))
122122
)
123123
})
124124

@@ -134,8 +134,8 @@ test_that("weird cases", {
134134
# So model.frame ignores - signs in a model formula so class is not removed
135135
# prior to model.matrix; otherwise this should have n_cols = 3
136136
expect_equal(
137-
template(3, 4, 150, NA, 1, hpc, hpc[-2], hpc[,"compounds"]),
138-
eval_descrs(get_descr_form(compounds ~ . - class, data = hpc))
137+
template(3, 4, 150, NA, 1, hpc, hpc[-2], hpc[,"input_fields"]),
138+
eval_descrs(get_descr_form(input_fields ~ . - class, data = hpc))
139139
)
140140

141141
# Oy ve! Before going to model.matrix, model.frame produces a data frame
@@ -173,7 +173,7 @@ test_that("numeric y and dummy vars", {
173173
eval_descrs(get_descr_xy(x = hpc[, 4:5], y = hpc[, 1:2]))
174174
)
175175

176-
hpc3 <- hpc2[,c("iterations", "class", "input_fields")]
176+
hpc3 <- hpc2[,c("num_pending", "class", "compounds")]
177177
expect_equal(
178178
template(2, 2, 150, NA, 1, hpc3, hpc[, 4:5], hpc[, 1, drop = FALSE]),
179179
eval_descrs(get_descr_xy(x = hpc[, 4:5], y = hpc[, 1, drop = FALSE]))

0 commit comments

Comments
 (0)