Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbaniecki committed May 6, 2020
1 parent 049b3c8 commit 18367a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
26 changes: 15 additions & 11 deletions tests/testthat/test_ms_update_observations.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ context("Check ms_update_observations() function")

source("test_objects.R")

ms <- modelStudio::modelStudio(explain_rf, apartments[1:2,], N = 5, B = 2)
ms <- modelStudio::modelStudio(explain_rf, apartments[1:2,], N = 5, B = 2, show_info = v)

testthat::test_that("modelStudio class", {
testthat::expect_is(ms, "modelStudio")
testthat::expect_silent(ms)
})

new_ms1 <- modelStudio::ms_update_options(ms, explain_rf, B = 3)
new_ms2 <- modelStudio::ms_update_options(ms, explain_rf,
new_observation = apartments[100:101,],
B = 3, overwrite = FALSE)
new_ms3 <- modelStudio::ms_update_options(ms, explain_rf,
new_observation = apartments[1:2,],
B = 3, overwrite = TRUE)
new_ms1 <- modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v)
new_ms2 <- modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[100:101,],
overwrite = FALSE)
new_ms3 <- modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1:2,],
overwrite = TRUE)

testthat::test_that("ms_update_observations", {
testthat::expect_is(new_ms1, "modelStudio")
testthat::expect_silent(new_ms1)
testthat::expect_silent(modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v))
testthat::expect_is(new_ms2, "modelStudio")
testthat::expect_silent(new_ms2)
testthat::expect_silent(modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[100:101,],
overwrite = FALSE))
testthat::expect_is(new_ms3, "modelStudio")
testthat::expect_silent(new_ms3)
testthat::expect_silent(modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1:2,],
overwrite = TRUE))
})
16 changes: 8 additions & 8 deletions tests/testthat/test_warnings_and_errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ testthat::test_that("new_observation as list", {
testthat::expect_warning(
modelStudio::modelStudio(explain_glm,
new_observation = as.list(titanic_test[1,-9]),
show_info = v)
show_info = v, B = 3)
)
})

testthat::test_that("check_single_prediction error", {
testthat::expect_error(
modelStudio::modelStudio(explainer_xgb,
new_observation = model_matrix_train[1,],
show_info = v)
show_info = v, B = 3)
)
})

Expand All @@ -25,15 +25,15 @@ testthat::test_that("deprecated modelStudioOptions", {
})

ms <- modelStudio::modelStudio(explain_rf, apartments[1:2,], N = 5, B = 2, show_info = v)
new_ms <- modelStudio::ms_update_options(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1,],
new_observation_y = apartments$m2.price[1])
new_ms <- modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1,],
new_observation_y = apartments$m2.price[1])

testthat::test_that("duplicated ids", {
testthat::expect_is(new_ms, "modelStudio")
testthat::expect_warning(
modelStudio::ms_update_options(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1,],
new_observation_y = apartments$m2.price[1])
modelStudio::ms_update_observations(ms, explain_rf, B = 2, show_info = v,
new_observation = apartments[1,],
new_observation_y = apartments$m2.price[1])
)
})

0 comments on commit 18367a3

Please sign in to comment.