Skip to content

Commit

Permalink
Merge pull request #248 from oxford-pharmacoepi/mike-dev
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 b0bd52a + f377688 commit d192b71
Showing 1 changed file with 62 additions and 24 deletions.
86 changes: 62 additions & 24 deletions tests/testthat/test-summariseTemporalSymmetry.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
test_that("test summariseTemporalSymmetry", {

cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2")
temporal_symmetry <- summariseTemporalSymmetry(cohort = cdm$joined_cohorts)

expect_true(
all(names(temporal_symmetry) %in% c(
"result_id",
"cdm_name",
"group_name",
"group_level",
"strata_name",
"strata_level",
"variable_name",
"variable_level",
"estimate_name",
"estimate_type",
"estimate_value",
"additional_name",
"additional_level"
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(
cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2"
)
))
temporal_symmetry <-
summariseTemporalSymmetry(cohort = cdm$joined_cohorts)

expect_true(all(
names(temporal_symmetry) %in% c(
"result_id",
"cdm_name",
"group_name",
"group_level",
"strata_name",
"strata_level",
"variable_name",
"variable_level",
"estimate_name",
"estimate_type",
"estimate_value",
"additional_name",
"additional_level"
)
))

expect_true(is.na(temporal_symmetry$estimate_value |> unique()))

temporal_symmetry <-
summariseTemporalSymmetry(cohort = cdm$joined_cohorts, minCellCount = 0)

expect_true(all(!is.na(
temporal_symmetry$estimate_value |> unique()
)))

time <-
cdm$joined_cohorts %>% dplyr::filter(cohort_definition_id == 1) %>%
dplyr::mutate(time = as.numeric(
!!CDMConnector::datediff("index_date", "marker_date", interval = "month")
)) |> dplyr::pull(time)

time2 <-
temporal_symmetry %>% dplyr::filter(group_level == "cohort_1 &&& cohort_1") |> dplyr::pull(variable_level) |> as.double()

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


temporal_symmetry <-
summariseTemporalSymmetry(
cohort = cdm$joined_cohorts,
minCellCount = 0,
timescale = "day"
)

time <-
cdm$joined_cohorts %>% dplyr::filter(cohort_definition_id == 1) %>%
dplyr::mutate(time = as.numeric(
!!CDMConnector::datediff("index_date", "marker_date", interval = "day")
)) |> dplyr::pull(time)

time2 <-
temporal_symmetry %>% dplyr::filter(group_level == "cohort_1 &&& cohort_1") |> dplyr::pull(variable_level) |> as.double()

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

0 comments on commit d192b71

Please sign in to comment.