From 6cf6d2f7dd875a87910df8a72214249cc13811b7 Mon Sep 17 00:00:00 2001 From: njlyon0 Date: Wed, 15 May 2024 17:33:39 -0400 Subject: [PATCH] First pass at `diff_check` unit testing --- tests/testthat/test-diff_check.R | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/testthat/test-diff_check.R diff --git a/tests/testthat/test-diff_check.R b/tests/testthat/test-diff_check.R new file mode 100644 index 0000000..e079ae1 --- /dev/null +++ b/tests/testthat/test-diff_check.R @@ -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") +}) \ No newline at end of file