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