From a913d6b125182db8327fa7d07c42a18cf5ce8c10 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 8 Nov 2024 16:13:56 -0800 Subject: [PATCH] lint expect_snapshot() --- tests/testthat/test-adasyn.R | 15 ++++++++++----- tests/testthat/test-adasyn_impl.R | 21 ++++++++++++++------- tests/testthat/test-bsmote.R | 12 ++++++++---- tests/testthat/test-bsmote_impl.R | 21 ++++++++++++++------- tests/testthat/test-downsample.R | 9 ++++++--- tests/testthat/test-nearmiss.R | 12 ++++++++---- tests/testthat/test-rose.R | 12 ++++++++---- tests/testthat/test-smote.R | 15 ++++++++++----- tests/testthat/test-smote_impl.R | 21 ++++++++++++++------- tests/testthat/test-tomek.R | 12 ++++++++---- tests/testthat/test-tomek_impl.R | 20 ++++++++++++-------- tests/testthat/test-upsample.R | 9 ++++++--- 12 files changed, 118 insertions(+), 61 deletions(-) diff --git a/tests/testthat/test-adasyn.R b/tests/testthat/test-adasyn.R index 698a2ed..3bd0630 100644 --- a/tests/testthat/test-adasyn.R +++ b/tests/testthat/test-adasyn.R @@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", { credit_data0$Status[1] <- "dummy" credit_data0$Status <- as.factor(credit_data0$Status) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Status ~ Age, data = credit_data0) %>% step_adasyn(Status) %>% prep() @@ -32,13 +33,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_adasyn(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_adasyn(class, id) %>% prep() @@ -52,7 +55,8 @@ test_that("errors if character are present", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_adasyn(x) %>% prep() @@ -64,7 +68,8 @@ test_that("NA in response", { data("credit_data", package = "modeldata") - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Job ~ Age, data = credit_data) %>% step_adasyn(Job) %>% prep() diff --git a/tests/testthat/test-adasyn_impl.R b/tests/testthat/test-adasyn_impl.R index 4e9127c..0b43f46 100644 --- a/tests/testthat/test-adasyn_impl.R +++ b/tests/testthat/test-adasyn_impl.R @@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")] test_that("adasyn() interfaces correctly", { expect_no_error(adasyn(circle_example_num, var = "class")) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = "Class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = c("class", "x")) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = "x") ) circle_example0 <- circle_example_num circle_example0[1, 1] <- NA - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example0, var = "class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = "class", k = 0) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = "class", k = -1) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, adasyn(circle_example_num, var = "class", k = c(5, 10)) ) }) diff --git a/tests/testthat/test-bsmote.R b/tests/testthat/test-bsmote.R index 595ad3d..58812e4 100644 --- a/tests/testthat/test-bsmote.R +++ b/tests/testthat/test-bsmote.R @@ -44,13 +44,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_bsmote(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_bsmote(class, id) %>% prep() @@ -64,7 +66,8 @@ test_that("errors if character are present", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_bsmote(x) %>% prep() @@ -76,7 +79,8 @@ test_that("NA in response", { data("credit_data", package = "modeldata") - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Job ~ Age, data = credit_data) %>% step_bsmote(Job) %>% prep() diff --git a/tests/testthat/test-bsmote_impl.R b/tests/testthat/test-bsmote_impl.R index 7084584..72412b9 100644 --- a/tests/testthat/test-bsmote_impl.R +++ b/tests/testthat/test-bsmote_impl.R @@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")] test_that("bsmote() interfaces correctly", { expect_no_error(bsmote(circle_example_num, var = "class")) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = "Class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = c("class", "x")) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = "x") ) circle_example0 <- circle_example_num circle_example0[1, 1] <- NA - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example0, var = "class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = "class", k = 0) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = "class", k = -1) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, bsmote(circle_example_num, var = "class", k = c(5, 10)) ) }) diff --git a/tests/testthat/test-downsample.R b/tests/testthat/test-downsample.R index b3c76da..ad66beb 100644 --- a/tests/testthat/test-downsample.R +++ b/tests/testthat/test-downsample.R @@ -1,5 +1,6 @@ test_that("ratio deprecation", { - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, new_rec <- recipe(~., data = circle_example) %>% step_downsample(class, ratio = 2) ) @@ -22,13 +23,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_downsample(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_downsample(class, id) %>% prep() diff --git a/tests/testthat/test-nearmiss.R b/tests/testthat/test-nearmiss.R index 8557c6d..43d33f5 100644 --- a/tests/testthat/test-nearmiss.R +++ b/tests/testthat/test-nearmiss.R @@ -15,13 +15,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_nearmiss(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_nearmiss(class, id) %>% prep() @@ -35,7 +37,8 @@ test_that("errors if character are present", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_nearmiss(x) %>% prep() @@ -47,7 +50,8 @@ test_that("NA in response", { data("credit_data", package = "modeldata") - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Job ~ Age, data = credit_data) %>% step_nearmiss(Job) %>% prep() diff --git a/tests/testthat/test-rose.R b/tests/testthat/test-rose.R index 2d1950b..81ff978 100644 --- a/tests/testthat/test-rose.R +++ b/tests/testthat/test-rose.R @@ -54,13 +54,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_rose(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_rose(class, id) %>% prep() @@ -74,7 +76,8 @@ test_that("NA in response", { credit_data0 <- credit_data credit_data0[1, 1] <- NA - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Status ~ Age, data = credit_data0) %>% step_rose(Status) %>% prep() @@ -124,7 +127,8 @@ test_that("only except 2 classes", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_rose(x) %>% prep() diff --git a/tests/testthat/test-smote.R b/tests/testthat/test-smote.R index 3e129bd..f88ea80 100644 --- a/tests/testthat/test-smote.R +++ b/tests/testthat/test-smote.R @@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", { credit_data0$Status[1] <- "dummy" credit_data0$Status <- as.factor(credit_data0$Status) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Status ~ Age, data = credit_data0) %>% step_smote(Status) %>% prep() @@ -32,13 +33,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_smote(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_smote(class, id) %>% prep() @@ -52,7 +55,8 @@ test_that("errors if character are present", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_smote(x) %>% prep() @@ -64,7 +68,8 @@ test_that("NA in response", { data("credit_data", package = "modeldata") - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Job ~ Age, data = credit_data) %>% step_smote(Job) %>% prep() diff --git a/tests/testthat/test-smote_impl.R b/tests/testthat/test-smote_impl.R index f880c14..f5cb93a 100644 --- a/tests/testthat/test-smote_impl.R +++ b/tests/testthat/test-smote_impl.R @@ -24,34 +24,41 @@ test_that("smote() interfaces correctly", { expect_no_error(smote(circle_example_num, var = "class")) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = "Class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = c("class", "x")) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = "x") ) circle_example0 <- circle_example_num circle_example0[1, 1] <- NA - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example0, var = "class") ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = "class", k = 0) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = "class", k = -1) ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, smote(circle_example_num, var = "class", k = c(5, 10)) ) }) diff --git a/tests/testthat/test-tomek.R b/tests/testthat/test-tomek.R index e1d46fd..61af006 100644 --- a/tests/testthat/test-tomek.R +++ b/tests/testthat/test-tomek.R @@ -15,13 +15,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_smote(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_smote(class, id) %>% prep() @@ -35,7 +37,8 @@ test_that("errors if character are present", { stringsAsFactors = FALSE ) - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(~., data = df_char) %>% step_tomek(x) %>% prep() @@ -49,7 +52,8 @@ test_that("NA in response", { credit_data0 <- credit_data credit_data0[1, 1] <- NA - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, recipe(Status ~ Age, data = credit_data0) %>% step_tomek(Status) %>% prep() diff --git a/tests/testthat/test-tomek_impl.R b/tests/testthat/test-tomek_impl.R index 7c5bb0d..bba898d 100644 --- a/tests/testthat/test-tomek_impl.R +++ b/tests/testthat/test-tomek_impl.R @@ -19,23 +19,27 @@ test_that("tomek() interfaces correctly", { expect_no_error(tomek(circle_example_num, var = "class")) - expect_snapshot(error = TRUE, - tomek(circle_example_num, var = "Class") + expect_snapshot( + error = TRUE, + tomek(circle_example_num, var = "Class") ) - expect_snapshot(error = TRUE, - tomek(circle_example_num, var = c("class", "x")) + expect_snapshot( + error = TRUE, + tomek(circle_example_num, var = c("class", "x")) ) - expect_snapshot(error = TRUE, - tomek(circle_example_num, var = "x") + expect_snapshot( + error = TRUE, + tomek(circle_example_num, var = "x") ) circle_example0 <- circle_example_num circle_example0[1, 1] <- NA - expect_snapshot(error = TRUE, - tomek(circle_example0, var = "class") + expect_snapshot( + error = TRUE, + tomek(circle_example0, var = "class") ) }) diff --git a/tests/testthat/test-upsample.R b/tests/testthat/test-upsample.R index eddc617..57b76db 100644 --- a/tests/testthat/test-upsample.R +++ b/tests/testthat/test-upsample.R @@ -1,5 +1,6 @@ test_that("ratio deprecation", { - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, new_rec <- recipe(~., data = circle_example) %>% step_upsample(class, ratio = 2) ) @@ -22,13 +23,15 @@ test_that("basic usage", { test_that("bad data", { rec <- recipe(~., data = circle_example) # numeric check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_upsample(x) %>% prep() ) # Multiple variable check - expect_snapshot(error = TRUE, + expect_snapshot( + error = TRUE, rec %>% step_upsample(class, id) %>% prep()