-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at
diff_check
unit testing
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Run all tests in this script: | ||
## testthat::test_file(file.path("tests", "testthat", "test-diff_check.R")) | ||
|
||
# Error testing | ||
test_that("Errors work as desired", { | ||
|
||
# Make two vectors | ||
vec1 <- c("x", "a", "b") | ||
vec2 <- c("y", "z", "a") | ||
|
||
# Inputs testing | ||
expect_error(diff_check(old = NULL, new = vec2, sort = TRUE, return = TRUE)) | ||
expect_error(diff_check(old = vec1, new = NULL, sort = TRUE, return = TRUE)) | ||
expect_error(diff_check(old = as.data.frame(vec1), new = vec2, sort = TRUE, return = TRUE)) | ||
expect_error(diff_check(old = vec1, new = as.data.frame(vec2), sort = TRUE, return = TRUE)) | ||
}) | ||
|
||
# Warning testing | ||
test_that("Warnings work as desired", { | ||
|
||
# Make two vectors | ||
vec1 <- c("x", "a", "b") | ||
vec2 <- c("y", "z", "a") | ||
|
||
# Expected warning contexts | ||
expect_warning(diff_check(old = vec1, new = vec2, sort = "true", return = TRUE)) | ||
expect_warning(diff_check(old = vec1, new = vec2, sort = TRUE, return = "true")) | ||
}) | ||
|
||
# Message testing | ||
test_that("Messages work as desired", { | ||
|
||
# Make two vectors | ||
vec1 <- c("x", "a", "b") | ||
vec2 <- c("y", "z", "a") | ||
|
||
# Expected message contexts | ||
expect_message(diff_check(old = vec1, new = vec2, sort = FALSE, return = FALSE)) | ||
}) | ||
|
||
# Output testing | ||
test_that("Outputs are as expected", { | ||
|
||
# Make two vectors | ||
vec1 <- c("x", "a", "b") | ||
vec2 <- c("y", "z", "a") | ||
|
||
# Compare | ||
diff_out <- diff_check(old = vec1, new = vec2, sort = FALSE, return = TRUE) | ||
|
||
# Expected outputs | ||
expect_equal(class(diff_out), "list") | ||
}) |