Skip to content

Commit

Permalink
Merge branch 'main' into hugo-misc-july2024
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsantiagoquevedo authored Jul 22, 2024
2 parents dd766d7 + 29f9910 commit aa93ad9
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 6 deletions.
151 changes: 151 additions & 0 deletions tests/testthat/_snaps/match_cohort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# `match_cohort`: summary snapshot

{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["balance_all"]
}
},
"value": [
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["u", "v", "smd"]
},
"row.names": {
"type": "character",
"attributes": {},
"value": ["age", "sex_F", "sex_M"]
},
"class": {
"type": "character",
"attributes": {},
"value": ["data.frame"]
}
},
"value": [
{
"type": "double",
"attributes": {},
"value": [30.18416801, 0.5088853, 0.4911147]
},
{
"type": "double",
"attributes": {},
"value": [47.51706037, 0.54855643, 0.45144357]
},
{
"type": "double",
"attributes": {},
"value": [0.87245622, 0.0795363, -0.0795363]
}
]
}
]
}

---

{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["balance_match"]
}
},
"value": [
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["u", "v", "smd"]
},
"row.names": {
"type": "character",
"attributes": {},
"value": ["age", "sex_F", "sex_M"]
},
"class": {
"type": "character",
"attributes": {},
"value": ["data.frame"]
}
},
"value": [
{
"type": "double",
"attributes": {},
"value": [42.4760479, 0.54491018, 0.45508982]
},
{
"type": "double",
"attributes": {},
"value": [44.74850299, 0.54491018, 0.45508982]
},
{
"type": "double",
"attributes": {},
"value": [0.1227198, 0, 0]
}
]
}
]
}

---

{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["summary"]
}
},
"value": [
{
"type": "list",
"attributes": {
"names": {
"type": "character",
"attributes": {},
"value": ["u", "v"]
},
"row.names": {
"type": "character",
"attributes": {},
"value": ["All", "Matched", "Unmatched", "Removed"]
},
"class": {
"type": "character",
"attributes": {},
"value": ["data.frame"]
}
},
"value": [
{
"type": "integer",
"attributes": {},
"value": [619, 338, 281, 4]
},
{
"type": "integer",
"attributes": {},
"value": [381, 338, 43, 4]
}
]
}
]
}

12 changes: 6 additions & 6 deletions tests/testthat/test-match_cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end_cohort <- as.Date("2044-12-31")

# sample cohort to make tests faster - take a bigger sample
sample_size <- 1000
set.seed(123) #use fixed seed to avoid problems with snapshots
set.seed(123) # use fixed seed to avoid problems with snapshots
sample_indices <- sample(nrow(cohortdata), sample_size)
sample_cohort <- cohortdata[sample_indices, ]
rownames(sample_cohort) <- NULL
Expand Down Expand Up @@ -68,8 +68,8 @@ test_that("`match_cohort`: test for input validation", {
})

#### Snapshot for summary
# test_that("`match_cohort`: summary snapshot", { #nolint
# # snapshot for summary
# summ <- capture.output(summary.match(matching)) #nolint
# expect_snapshot(summ) #nolint
# })
test_that("`match_cohort`: summary snapshot", { # nolint
for (column in c("balance_all", "balance_match", "summary")) {
expect_snapshot_value(matching[column], style = "json2", tolerance = 1e-2)
}
})

0 comments on commit aa93ad9

Please sign in to comment.