Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 committed Jan 9, 2024
1 parent 5c7eecf commit 6aacf5b
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 314 deletions.
147 changes: 0 additions & 147 deletions tests/testthat/test-add_smr_type.R

This file was deleted.

147 changes: 147 additions & 0 deletions tests/testthat/test-add_smrtype.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Single character input
test_that("SMR type works for single input", {
expect_equal(
add_smrtype(recid = "02B", mpat = "0"),
"Matern-HB"
)
expect_equal(
add_smrtype(recid = "02B", mpat = "1"),
"Matern-IP"
)
expect_equal(
add_smrtype(recid = "02B", mpat = "4"),
"Matern-DC"
)
expect_equal(
add_smrtype(recid = "04B"),
"Psych-IP"
)
expect_equal(
add_smrtype(recid = "00B"),
"Outpatient"
)
expect_equal(
add_smrtype(recid = "AE2"),
"A & E"
)
expect_equal(
add_smrtype(recid = "PIS"),
"PIS"
)
expect_equal(
add_smrtype(recid = "NRS"),
"NRS Deaths"
)
expect_equal(
add_smrtype(recid = "CMH"),
"Comm-MH"
)
expect_equal(
add_smrtype(recid = "DN"),
"DN"
)
expect_equal(
add_smrtype(recid = "01B", ipdc = "I"),
"Acute-IP"
)
expect_equal(
add_smrtype(recid = "01B", ipdc = "D"),
"Acute-DC"
)
expect_equal(
add_smrtype(recid = "GLS", ipdc = "I"),
"GLS-IP"
)
expect_equal(
add_smrtype(recid = "HC", hc_service = 1L),
"HC-Non-Per"
)
expect_equal(
add_smrtype(recid = "HC", hc_service = 2L),
"HC-Per"
)
expect_equal(
add_smrtype(recid = "HC", hc_service = 3L),
"HC-Unknown"
)
expect_equal(
add_smrtype(recid = "HL1", main_applicant_flag = "Y"),
"HL1-Main"
)
expect_equal(
add_smrtype(recid = "HL1", main_applicant_flag = "N"),
"HL1-Other"
)
})

# Vector input
test_that("SMR type works for vector input", {
expect_equal(
add_smrtype(recid = c("04B", "00B", "PIS", "AE2", "NRS", "CMH")),
c("Psych-IP", "Outpatient", "PIS", "A & E", "NRS Deaths", "Comm-MH")
)
expect_equal(
add_smrtype(recid = c("02B", "02B", "02B"), mpat = c("5", "6", "A")),
c("Matern-IP", "Matern-DC", "Matern-IP")
)
expect_equal(
add_smrtype(recid = c("01B", "01B", "GLS"), ipdc = c("I", "D", "I")),
c("Acute-IP", "Acute-DC", "GLS-IP")
)
expect_equal(
add_smrtype(recid = c("HC", "HC", "HC"), hc_service = c(1L, 2L, 3L)),
c("HC-Non-Per", "HC-Per", "HC-Unknown")
)
expect_equal(
add_smrtype(recid = c("HL1", "HL1"), main_applicant_flag = c("N", "Y")),
c("HL1-Other", "HL1-Main")
)
})

# Informational messages
test_that("Warnings return as expected", {
expect_warning(
add_smrtype(recid = c("00B", "AE2", "Bum", "PIS")),
"One or more values of `recid` do not"
) %>%
expect_warning(
"Some `smrtype`s were not properly set"
)
})

# Errors that abort the function
test_that("Error escapes functions as expected", {
expect_error(
add_smrtype(recid = c(NA, NA, "04B"))
)
expect_error(
add_smrtype(recid = c("02B", "02B"), mpat = c(NA, "1"))
)
expect_error(
add_smrtype(recid = c("01B", "GLS"), ipdc = c(NA, NA))
)
expect_warning(
add_smrtype(recid = c("01B", "GLS"), ipdc = c(NA, "I"))
)
expect_error(
add_smrtype(recid = c("HC", "HC"), hc_service = c(NA, 1L))
)
expect_error(
add_smrtype(recid = c("HL1", "HL1"), main_applicant_flag = c(NA, "Y"))
)
expect_error(
add_smrtype(recid = c(NA, NA, NA, NA))
)
expect_error(
add_smrtype(recid = c("02B", "02B", "02B"))
)
expect_error(
add_smrtype(recid = c("01B", "GLS"))
)
expect_error(
add_smrtype(recid = c("HC", "HC"))
)
expect_error(
add_smrtype(recid = c("HL1", "HL1"))
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-check_year_valid.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test_that("Check year valid works for specific datasets ", {
expect_true(check_year_valid("2122", "sparra"))
expect_true(check_year_valid("2122", "sparra"))
expect_true(check_year_valid("2223", "sparra"))
expect_false(check_year_valid("2324", "sparra"))
expect_true(check_year_valid("2324", "sparra"))

# HHG
expect_false(check_year_valid("1415", "hhg"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-get_dd_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("Delayed discharges file exists", {
latest_dd_path <- get_dd_path()

expect_s3_class(latest_dd_path, "fs_path")
expect_equal(fs::path_ext(latest_dd_path), "rds")
expect_equal(fs::path_ext(latest_dd_path), "parquet")
})

test_that("Delayed discharges file is as expected", {
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-get_gpprac_opendata.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ skip_if_offline()
test_that("GP prac cluster lookup is correct", {
gp_cluster_lookup <- expect_warning(get_gpprac_opendata())

expect_s3_class(gp_cluster_lookup, "tbl_df")
expect_named(
gp_cluster_lookup,
c(
Expand Down
Loading

0 comments on commit 6aacf5b

Please sign in to comment.