Skip to content

Commit

Permalink
Changed to expect_snapshot_value to check with tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
jpavlich authored and davidsantiagoquevedo committed Jul 22, 2024
1 parent 1d3413a commit 29f9910
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 95 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]
}
]
}
]
}

4 changes: 0 additions & 4 deletions tests/testthat/_snaps/match_cohort/balance_all.csv

This file was deleted.

4 changes: 0 additions & 4 deletions tests/testthat/_snaps/match_cohort/balance_match.csv

This file was deleted.

4 changes: 0 additions & 4 deletions tests/testthat/_snaps/match_cohort/summary.csv

This file was deleted.

74 changes: 0 additions & 74 deletions tests/testthat/helper-functions.R

This file was deleted.

11 changes: 2 additions & 9 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 @@ -70,13 +70,6 @@ test_that("`match_cohort`: test for input validation", {
#### Snapshot for summary
test_that("`match_cohort`: summary snapshot", { # nolint
for (column in c("balance_all", "balance_match", "summary")) {
expect_similar_dataframes(
column, matching$balance_match,
list(
u = equal_with_tolerance(),
v = equal_with_tolerance(),
smd = equal_with_tolerance()
)
)
expect_snapshot_value(matching[column], style = "json2", tolerance = 1e-2)
}
})

0 comments on commit 29f9910

Please sign in to comment.