Skip to content

Commit

Permalink
Merge pull request #249 from oxford-pharmacoepi/final_checks_010
Browse files Browse the repository at this point in the history
Update test-summariseTemporalSymmetry.R
  • Loading branch information
xihang-chen authored May 29, 2024
2 parents bf525a9 + 7ccd48d commit c3debd6
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions tests/testthat/test-summariseTemporalSymmetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,103 @@ test_that("test summariseTemporalSymmetry", {
temporal_symmetry %>% dplyr::filter(group_level == "cohort_1 &&& cohort_1") |> dplyr::pull(variable_level) |> as.double()

expect_true(all(sum(time) == sum(time2)))

CDMConnector::cdmDisconnect(cdm = cdm)
})

test_that("test cohortId",{
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(
cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2"
)

result <- summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
cohortId = 1)

expect_equal(omopgenerics::settings(result) %>%
nrow()|>
as.numeric(), 1)

expect_true((result %>%
dplyr::select(group_level) %>%
dplyr::distinct(group_level) %>%
dplyr::pull(group_level)) == "cohort_1 &&& cohort_1")

CDMConnector::cdm_disconnect(cdm = cdm)
})

test_that("input validation",{
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(
cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2"
)

expect_no_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts)
)

expect_no_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
cohortId = 1)
)

expect_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
timescale = "quarter")
)

expect_no_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
timescale = "day")
)

expect_no_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
timescale = "year")
)

expect_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
cohortId = "one")
)

expect_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
cohortId = "1")
)

expect_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
minCellCount = -1)
)

expect_error(
summariseTemporalSymmetry(cohort = cdm$joined_cohorts,
minCellCount = Inf)
)

CDMConnector::cdmDisconnect(cdm = cdm)

})

test_that("edge case",{
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(
cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2",
combinationWindow = c(10, 11)
)

expect_error(
result <- summariseTemporalSymmetry(cohort = cdm$joined_cohorts)
)

})

0 comments on commit c3debd6

Please sign in to comment.