From 67720895761a3864fb32cf5cc01c716618cc496f Mon Sep 17 00:00:00 2001 From: Maarten van Kessel Date: Fri, 1 Sep 2023 09:37:38 +0200 Subject: [PATCH] Added result tests for refitPsForEveryOutcome --- tests/testthat/test-runCmAnalyses.R | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/testthat/test-runCmAnalyses.R b/tests/testthat/test-runCmAnalyses.R index f69c1edc..ef26ee2e 100644 --- a/tests/testthat/test-runCmAnalyses.R +++ b/tests/testthat/test-runCmAnalyses.R @@ -443,6 +443,50 @@ test_that("refitPsForEveryOutcome", { # Throws Error: # cannot open file '.\Temp\RtmpwLKCGK\cmData6dbc562227db': it is a directory + ### Check files ---- + refitTrue <- suppressWarnings(runCmAnalyses( + connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + exposureTable = "cohort", + outcomeTable = "cohort", + outputFolder = outputFolder, + cmAnalysisList = cmAnalysisList, + targetComparatorOutcomesList = targetComparatorOutcomesList, + refitPsForEveryOutcome = TRUE + )) + + refitFalse <- suppressWarnings(runCmAnalyses( + connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + exposureTable = "cohort", + outcomeTable = "cohort", + outputFolder = outputFolder, + cmAnalysisList = cmAnalysisList, + targetComparatorOutcomesList = targetComparatorOutcomesList, + refitPsForEveryOutcome = FALSE + )) + + expect_false(identical(refitTrue, refitFalse)) + expect_true(all(grepl( + pattern = "(^StudyPop_l1_s\\d+_t\\d+_c\\d+_o\\d+\\.rds$|^$)", + x = c(refitTrue$studyPopFile, refitFalse$studyPopFile) + ))) + + expect_true(all(grepl( + pattern = "(^Ps_l1_s\\d+_p\\d+_t\\d+_c\\d+\\.rds$|^$)", + x = c(refitTrue$sharedPsFile, refitFalse$sharedPsFile) + ))) + + expect_true(all(grepl( + pattern = "(^Ps_l1_s\\d+_p\\d+_t\\d+_c\\d+_o\\d+\\.rds$|^$)", + x = c(refitTrue$psFile, refitFalse$psFile) + ))) + + expect_true(all(grepl( + pattern = "(^Balance_l1_s\\d+_p\\d+_t\\d+_c\\d+_s\\d+_b\\d+\\.rds$|^$)", + x = c(refitTrue$sharedBalanceFile, refitFalse$sharedBalanceFile) + ))) + ### 0 ---- unlink(outputFolder, recursive = TRUE) expect_error(