test_lgb.importance.R 974 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
test_that("lgb.importance() should reject bad inputs", {
    bad_inputs <- list(
        .Machine$integer.max
        , Inf
        , -Inf
        , NA
        , NA_real_
        , -10L:10L
        , list(c("a", "b", "c"))
        , data.frame(
11
            x = rnorm(20L)
12
            , y = sample(
13
14
                x = c(1L, 2L)
                , size = 20L
15
16
17
18
                , replace = TRUE
            )
        )
        , data.table::data.table(
19
            x = rnorm(20L)
20
            , y = sample(
21
22
                x = c(1L, 2L)
                , size = 20L
23
24
25
26
                , replace = TRUE
            )
        )
        , lgb.Dataset(
27
28
            data = matrix(rnorm(100L), ncol = 2L)
            , label = matrix(sample(c(0L, 1L), 50L, replace = TRUE))
29
30
31
        )
        , "lightgbm.model"
    )
32
    for (input in bad_inputs) {
33
34
35
36
37
        expect_error({
            lgb.importance(input)
        }, regexp = "'model' has to be an object of class lgb\\.Booster")
    }
})