test_lgb.importance.R 1001 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
context("lgb.importance")

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(
13
            x = rnorm(20L)
14
            , y = sample(
15
16
                x = c(1L, 2L)
                , size = 20L
17
18
19
20
                , replace = TRUE
            )
        )
        , data.table::data.table(
21
            x = rnorm(20L)
22
            , y = sample(
23
24
                x = c(1L, 2L)
                , size = 20L
25
26
27
28
                , replace = TRUE
            )
        )
        , lgb.Dataset(
29
30
            data = matrix(rnorm(100L), ncol = 2L)
            , label = matrix(sample(c(0L, 1L), 50L, replace = TRUE))
31
32
33
        )
        , "lightgbm.model"
    )
34
    for (input in bad_inputs) {
35
36
37
38
39
        expect_error({
            lgb.importance(input)
        }, regexp = "'model' has to be an object of class lgb\\.Booster")
    }
})