Unverified Commit f9053abb authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package][tests] remove uses of `testthat::expect_is()` (#4916)

parent aa647d47
...@@ -394,7 +394,7 @@ test_that("CVBooster$reset_parameter() works as expected", { ...@@ -394,7 +394,7 @@ test_that("CVBooster$reset_parameter() works as expected", {
, nrounds = 3L , nrounds = 3L
, nfold = n_folds , nfold = n_folds
) )
expect_is(cv_bst, "lgb.CVBooster") expect_true(methods::is(cv_bst, "lgb.CVBooster"))
expect_length(cv_bst$boosters, n_folds) expect_length(cv_bst$boosters, n_folds)
for (bst in cv_bst$boosters) { for (bst in cv_bst$boosters) {
expect_equal(bst[["booster"]]$params[["num_leaves"]], 7L) expect_equal(bst[["booster"]]$params[["num_leaves"]], 7L)
...@@ -467,7 +467,7 @@ test_that("lightgbm.cv() gives the correct best_score and best_iter for a metric ...@@ -467,7 +467,7 @@ test_that("lightgbm.cv() gives the correct best_score and best_iter for a metric
, num_leaves = 5L , num_leaves = 5L
) )
) )
expect_is(cv_bst, "lgb.CVBooster") expect_true(methods::is(cv_bst, "lgb.CVBooster"))
expect_named( expect_named(
cv_bst$record_evals cv_bst$record_evals
, c("start_iter", "valid") , c("start_iter", "valid")
...@@ -505,7 +505,7 @@ test_that("lgb.cv() fit on linearly-relatead data improves when using linear lea ...@@ -505,7 +505,7 @@ test_that("lgb.cv() fit on linearly-relatead data improves when using linear lea
, params = params , params = params
, nfold = 5L , nfold = 5L
) )
expect_is(cv_bst, "lgb.CVBooster") expect_true(methods::is(cv_bst, "lgb.CVBooster"))
dtrain <- .new_dataset() dtrain <- .new_dataset()
cv_bst_linear <- lgb.cv( cv_bst_linear <- lgb.cv(
...@@ -514,7 +514,7 @@ test_that("lgb.cv() fit on linearly-relatead data improves when using linear lea ...@@ -514,7 +514,7 @@ test_that("lgb.cv() fit on linearly-relatead data improves when using linear lea
, params = utils::modifyList(params, list(linear_tree = TRUE)) , params = utils::modifyList(params, list(linear_tree = TRUE))
, nfold = 5L , nfold = 5L
) )
expect_is(cv_bst_linear, "lgb.CVBooster") expect_true(methods::is(cv_bst_linear, "lgb.CVBooster"))
expect_true(cv_bst_linear$best_score < cv_bst$best_score) expect_true(cv_bst_linear$best_score < cv_bst$best_score)
}) })
...@@ -549,7 +549,7 @@ test_that("lgb.cv() respects showsd argument", { ...@@ -549,7 +549,7 @@ test_that("lgb.cv() respects showsd argument", {
evals_showsd[["eval"]] evals_showsd[["eval"]]
, evals_no_showsd[["eval"]] , evals_no_showsd[["eval"]]
) )
expect_is(evals_showsd[["eval_err"]], "list") expect_true(methods::is(evals_showsd[["eval_err"]], "list"))
expect_equal(length(evals_showsd[["eval_err"]]), nrounds) expect_equal(length(evals_showsd[["eval_err"]]), nrounds)
expect_identical(evals_no_showsd[["eval_err"]], list()) expect_identical(evals_no_showsd[["eval_err"]], list())
}) })
......
...@@ -148,7 +148,10 @@ test_that("Dataset$set_reference() updates categorical_feature, colnames, and pr ...@@ -148,7 +148,10 @@ test_that("Dataset$set_reference() updates categorical_feature, colnames, and pr
dtest$set_reference(dtrain) dtest$set_reference(dtrain)
# after setting reference to dtrain, those attributes should have dtrain's values # after setting reference to dtrain, those attributes should have dtrain's values
expect_is(dtest$.__enclos_env__$private$predictor, "lgb.Predictor") expect_true(methods::is(
dtest$.__enclos_env__$private$predictor
, "lgb.Predictor"
))
expect_identical( expect_identical(
dtest$.__enclos_env__$private$predictor$.__enclos_env__$private$handle dtest$.__enclos_env__$private$predictor$.__enclos_env__$private$handle
, dtrain$.__enclos_env__$private$predictor$.__enclos_env__$private$handle , dtrain$.__enclos_env__$private$predictor$.__enclos_env__$private$handle
...@@ -199,7 +202,7 @@ test_that("lgb.Dataset: Dataset should be able to construct from matrix and retu ...@@ -199,7 +202,7 @@ test_that("lgb.Dataset: Dataset should be able to construct from matrix and retu
, lightgbm:::lgb.params2str(params = list()) , lightgbm:::lgb.params2str(params = list())
, ref_handle , ref_handle
) )
expect_is(handle, "externalptr") expect_true(methods::is(handle, "externalptr"))
expect_false(is.null(handle)) expect_false(is.null(handle))
.Call(LGBM_DatasetFree_R, handle) .Call(LGBM_DatasetFree_R, handle)
handle <- NULL handle <- NULL
...@@ -411,7 +414,7 @@ test_that("lgb.Dataset: should be able to run lgb.cv() immediately after using l ...@@ -411,7 +414,7 @@ test_that("lgb.Dataset: should be able to run lgb.cv() immediately after using l
, data = dtest_read_in , data = dtest_read_in
) )
expect_is(bst, "lgb.CVBooster") expect_true(methods::is(bst, "lgb.CVBooster"))
}) })
test_that("lgb.Dataset: should be able to use and retrieve long feature names", { test_that("lgb.Dataset: should be able to use and retrieve long feature names", {
......
...@@ -94,7 +94,7 @@ test_that("learning-to-rank with lgb.cv() works as expected", { ...@@ -94,7 +94,7 @@ test_that("learning-to-rank with lgb.cv() works as expected", {
, nrounds = nrounds , nrounds = nrounds
, nfold = nfold , nfold = nfold
) )
expect_is(cv_bst, "lgb.CVBooster") expect_true(methods::is(cv_bst, "lgb.CVBooster"))
expect_equal(length(cv_bst$boosters), nfold) expect_equal(length(cv_bst$boosters), nfold)
# "valid" should contain results for each metric # "valid" should contain results for each metric
......
...@@ -37,7 +37,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with onl ...@@ -37,7 +37,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with onl
expect_identical(converted_dataset[["col2"]], c(1L, 1L, 2L)) expect_identical(converted_dataset[["col2"]], c(1L, 1L, 2L))
# rules should be returned and correct # rules should be returned and correct
rules <- conversion_result$rules rules <- conversion_result$rules
expect_is(rules, "list") expect_true(methods::is(rules, "list"))
expect_length(rules, ncol(input_data)) expect_length(rules, ncol(input_data))
expect_identical(rules[["col1"]], c("a" = 1L, "b" = 2L, "c" = 3L)) expect_identical(rules[["col1"]], c("a" = 1L, "b" = 2L, "c" = 3L))
expect_identical(rules[["col2"]], c("green" = 1L, "red" = 2L)) expect_identical(rules[["col2"]], c("green" = 1L, "red" = 2L))
...@@ -62,7 +62,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with onl ...@@ -62,7 +62,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with onl
expect_identical(converted_dataset[["col2"]], c(1L, 1L, 2L)) expect_identical(converted_dataset[["col2"]], c(1L, 1L, 2L))
# rules should be returned and correct # rules should be returned and correct
rules <- conversion_result$rules rules <- conversion_result$rules
expect_is(rules, "list") expect_true(methods::is(rules, "list"))
expect_length(rules, ncol(input_data)) expect_length(rules, ncol(input_data))
expect_identical(rules[["col1"]], c("a" = 1L, "b" = 2L, "c" = 3L)) expect_identical(rules[["col1"]], c("a" = 1L, "b" = 2L, "c" = 3L))
expect_identical(rules[["col2"]], c("green" = 1L, "red" = 2L)) expect_identical(rules[["col2"]], c("green" = 1L, "red" = 2L))
...@@ -106,7 +106,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with num ...@@ -106,7 +106,7 @@ test_that("lgb.convert_with_rules() should work correctly for a dataset with num
expect_identical(converted_dataset[["factor_col"]], c(1L, 1L, 2L)) expect_identical(converted_dataset[["factor_col"]], c(1L, 1L, 2L))
# rules should be returned and correct # rules should be returned and correct
rules <- conversion_result$rules rules <- conversion_result$rules
expect_is(rules, "list") expect_true(methods::is(rules, "list"))
expect_length(rules, 2L) expect_length(rules, 2L)
expect_identical(rules[["character_col"]], c("a" = 1L, "b" = 2L, "c" = 3L)) expect_identical(rules[["character_col"]], c("a" = 1L, "b" = 2L, "c" = 3L))
expect_identical(rules[["factor_col"]], c("n" = 1L, "y" = 2L)) expect_identical(rules[["factor_col"]], c("n" = 1L, "y" = 2L))
...@@ -164,7 +164,7 @@ test_that("lgb.convert_with_rules() should convert missing values to the expecte ...@@ -164,7 +164,7 @@ test_that("lgb.convert_with_rules() should convert missing values to the expecte
# rules should be returned and correct # rules should be returned and correct
rules <- conversion_result$rules rules <- conversion_result$rules
expect_is(rules, "list") expect_true(methods::is(rules, "list"))
expect_length(rules, 3L) expect_length(rules, 3L)
expect_identical(rules[["character_col"]], c("a" = 1L, "c" = 2L)) expect_identical(rules[["character_col"]], c("a" = 1L, "c" = 2L))
expect_identical(rules[["factor_col"]], c("n" = 1L, "y" = 2L)) expect_identical(rules[["factor_col"]], c("n" = 1L, "y" = 2L))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment