Skip to content

Commit d080987

Browse files
committed
add tests
1 parent caf1829 commit d080987

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tests/testthat/test-mlp_keras.R

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,10 @@ car_basic <- mlp(mode = "regression", epochs = 10) %>%
149149

150150
bad_keras_reg <-
151151
mlp(mode = "regression") %>%
152-
set_engine("keras", min.node.size = -10)
152+
set_engine("keras", min.node.size = -10, verbose = 0)
153153

154154
# ------------------------------------------------------------------------------
155155

156-
157156
test_that('keras execution, regression', {
158157
skip_on_cran()
159158
skip_if_not_installed("keras")
@@ -211,7 +210,6 @@ test_that('keras regression prediction', {
211210
keras::backend()$clear_session()
212211
})
213212

214-
215213
# ------------------------------------------------------------------------------
216214

217215
test_that('multivariate nnet formula', {
@@ -247,3 +245,34 @@ test_that('multivariate nnet formula', {
247245

248246
keras::backend()$clear_session()
249247
})
248+
249+
# ------------------------------------------------------------------------------
250+
251+
test_that('all keras activation functions', {
252+
skip_on_cran()
253+
skip_if_not_installed("keras")
254+
skip_if_not_installed("modeldata")
255+
skip_if(!is_tf_ok())
256+
257+
act <- parsnip:::keras_activations()
258+
259+
test_act <- function(fn) {
260+
set.seed(1)
261+
try(
262+
mlp(mode = "classification", hidden_units = 2, penalty = 0.01, epochs = 2,
263+
activation = !!fn) %>%
264+
set_engine("keras", verbose = 0) %>%
265+
parsnip::fit(Class ~ A + B, data = modeldata::two_class_dat),
266+
silent = TRUE)
267+
268+
}
269+
test_act_sshhh <- purrr::quietly(test_act)
270+
271+
for (i in act) {
272+
keras::backend()$clear_session()
273+
act_res <- test_act_sshhh(i)
274+
expect_s3_class(act_res$result, "model_fit")
275+
keras::backend()$clear_session()
276+
}
277+
278+
})

0 commit comments

Comments
 (0)