Skip to content

Commit cc64f70

Browse files
committed
adjust tests to match
1 parent 8d9f2de commit cc64f70

File tree

2 files changed

+115
-48
lines changed

2 files changed

+115
-48
lines changed

tests/testthat/_snaps/revision-latency-functions.md

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
# revision_summary works for dummy datasets
22

33
Code
4-
dummy_ex %>% revision_summary() %>% print(n = 10, width = 300)
4+
rs1
55
Message
6-
Min lag (time to first version):
6+
7+
-- An epi_archive spanning 2020-01-01 to 2020-01-01. --
8+
9+
-- Min lag (time to first version):
710
Output
811
min median mean max
912
0 days 1 days 1.6 days 4 days
1013
Message
11-
Fraction of epi_key+time_values with
14+
15+
-- Fraction of epi_key + time_values with
1216
No revisions:
13-
* 3 out of 7 (42.86%)
17+
* 0 out of 7 (0%)
1418
Quick revisions (last revision within 3 days of the `time_value`):
1519
* 4 out of 7 (57.14%)
1620
Few revisions (At most 3 revisions for that `time_value`):
17-
* 6 out of 7 (85.71%)
18-
Fraction of revised epi_key+time_values which have:
21+
* 0 out of 7 (0%)
22+
23+
-- Fraction of revised epi_key + time_values which have:
1924
Less than 0.1 spread in relative value:
2025
* 1 out of 4 (25%)
2126
Spread of more than 5.1 in actual value (when revised):
2227
* 3 out of 4 (75%)
23-
Days until within 20% of the latest value:
28+
29+
-- Days until within 20% of the latest value:
2430
Output
2531
min median mean max
2632
0 days 3 days 6.9 days 19 days
33+
34+
---
35+
36+
Code
37+
rs1$revision_behavior %>% print(n = 10, width = 300)
38+
Output
2739
# A tibble: 7 x 11
2840
time_value geo_value n_revisions min_lag max_lag lag_near_latest spread
2941
<date> <chr> <dbl> <drtn> <drtn> <drtn> <dbl>
@@ -47,31 +59,43 @@
4759
---
4860

4961
Code
50-
dummy_ex %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300)
62+
rs2
5163
Message
52-
Min lag (time to first version):
64+
65+
-- An epi_archive spanning 2020-01-01 to 2020-01-01. --
66+
67+
-- Min lag (time to first version):
5368
Output
5469
min median mean max
5570
0 days 1 days 1.4 days 4 days
5671
Message
5772
Fraction of all versions that are `NA`:
5873
* 2 out of 19 (10.53%)
59-
Fraction of epi_key+time_values with
74+
75+
-- Fraction of epi_key + time_values with
6076
No revisions:
61-
* 2 out of 7 (28.57%)
77+
* 0 out of 7 (0%)
6278
Quick revisions (last revision within 3 days of the `time_value`):
6379
* 4 out of 7 (57.14%)
6480
Few revisions (At most 3 revisions for that `time_value`):
65-
* 6 out of 7 (85.71%)
66-
Fraction of revised epi_key+time_values which have:
81+
* 0 out of 7 (0%)
82+
83+
-- Fraction of revised epi_key + time_values which have:
6784
Less than 0.1 spread in relative value:
6885
* 2 out of 5 (40%)
6986
Spread of more than 5.1 in actual value (when revised):
7087
* 3 out of 5 (60%)
71-
Days until within 20% of the latest value:
88+
89+
-- Days until within 20% of the latest value:
7290
Output
7391
min median mean max
7492
0 days 3 days 6.9 days 19 days
93+
94+
---
95+
96+
Code
97+
rs2$revision_behavior %>% print(n = 10, width = 300)
98+
Output
7599
# A tibble: 7 x 11
76100
time_value geo_value n_revisions min_lag max_lag lag_near_latest spread
77101
<date> <chr> <dbl> <drtn> <drtn> <drtn> <dbl>
@@ -95,31 +119,43 @@
95119
---
96120

97121
Code
98-
dummy_ex_weekly %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300)
122+
rs3
99123
Message
100-
Min lag (time to first version):
124+
125+
-- An epi_archive spanning 2020-01-01 to 2020-01-01. --
126+
127+
-- Min lag (time to first version):
101128
Output
102129
min median mean max
103130
0 weeks 1 weeks 1.4 weeks 4 weeks
104131
Message
105132
Fraction of all versions that are `NA`:
106133
* 2 out of 19 (10.53%)
107-
Fraction of epi_key+time_values with
134+
135+
-- Fraction of epi_key + time_values with
108136
No revisions:
109-
* 2 out of 7 (28.57%)
137+
* 0 out of 7 (0%)
110138
Quick revisions (last revision within 1 week of the `time_value`):
111139
* 2 out of 7 (28.57%)
112140
Few revisions (At most 3 revisions for that `time_value`):
113-
* 6 out of 7 (85.71%)
114-
Fraction of revised epi_key+time_values which have:
141+
* 0 out of 7 (0%)
142+
143+
-- Fraction of revised epi_key + time_values which have:
115144
Less than 0.1 spread in relative value:
116145
* 2 out of 5 (40%)
117146
Spread of more than 5.1 in actual value (when revised):
118147
* 3 out of 5 (60%)
119-
Weeks until within 20% of the latest value:
148+
149+
-- Weeks until within 20% of the latest value:
120150
Output
121151
min median mean max
122152
0 weeks 3 weeks 6.9 weeks 19 weeks
153+
154+
---
155+
156+
Code
157+
rs3$revision_behavior %>% print(n = 10, width = 300)
158+
Output
123159
# A tibble: 7 x 11
124160
time_value geo_value n_revisions min_lag max_lag lag_near_latest spread
125161
<date> <chr> <dbl> <drtn> <drtn> <drtn> <dbl>
@@ -143,32 +179,43 @@
143179
---
144180

145181
Code
146-
dummy_ex_yearmonthly %>% revision_summary(drop_nas = FALSE) %>% print(n = 10,
147-
width = 300)
182+
rs4
148183
Message
149-
Min lag (time to first version):
184+
185+
-- An epi_archive spanning 2020 Jan to 2020 Jan. --
186+
187+
-- Min lag (time to first version):
150188
Output
151189
min median mean max
152190
0 1 1.4 4
153191
Message
154192
Fraction of all versions that are `NA`:
155193
* 2 out of 19 (10.53%)
156-
Fraction of epi_key+time_values with
194+
195+
-- Fraction of epi_key + time_values with
157196
No revisions:
158-
* 2 out of 7 (28.57%)
197+
* 0 out of 7 (0%)
159198
Quick revisions (last revision within 1 month of the `time_value`):
160199
* 2 out of 7 (28.57%)
161200
Few revisions (At most 3 revisions for that `time_value`):
162-
* 6 out of 7 (85.71%)
163-
Fraction of revised epi_key+time_values which have:
201+
* 0 out of 7 (0%)
202+
203+
-- Fraction of revised epi_key + time_values which have:
164204
Less than 0.1 spread in relative value:
165205
* 2 out of 5 (40%)
166206
Spread of more than 5.1 in actual value (when revised):
167207
* 3 out of 5 (60%)
168-
Months until within 20% of the latest value:
208+
209+
-- Months until within 20% of the latest value:
169210
Output
170211
min median mean max
171212
0 3 6.9 19
213+
214+
---
215+
216+
Code
217+
rs4$revision_behavior %>% print(n = 10, width = 300)
218+
Output
172219
# A tibble: 7 x 11
173220
time_value geo_value n_revisions min_lag max_lag lag_near_latest spread
174221
<mth> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
@@ -192,32 +239,43 @@
192239
---
193240

194241
Code
195-
dummy_ex_integerly %>% revision_summary(min_waiting_period = 60,
196-
quick_revision = 3, drop_nas = FALSE) %>% print(n = 10, width = 300)
242+
rs5
197243
Message
198-
Min lag (time to first version):
244+
245+
-- An epi_archive spanning 1 to 1. --
246+
247+
-- Min lag (time to first version):
199248
Output
200249
min median mean max
201250
0 1 1.4 4
202251
Message
203252
Fraction of all versions that are `NA`:
204253
* 2 out of 19 (10.53%)
205-
Fraction of epi_key+time_values with
254+
255+
-- Fraction of epi_key + time_values with
206256
No revisions:
207-
* 2 out of 7 (28.57%)
257+
* 0 out of 7 (0%)
208258
Quick revisions (last revision within 3 time steps of the `time_value`):
209259
* 4 out of 7 (57.14%)
210260
Few revisions (At most 3 revisions for that `time_value`):
211-
* 6 out of 7 (85.71%)
212-
Fraction of revised epi_key+time_values which have:
261+
* 0 out of 7 (0%)
262+
263+
-- Fraction of revised epi_key + time_values which have:
213264
Less than 0.1 spread in relative value:
214265
* 2 out of 5 (40%)
215266
Spread of more than 5.1 in actual value (when revised):
216267
* 3 out of 5 (60%)
217-
Time Steps until within 20% of the latest value:
268+
269+
-- Time Steps until within 20% of the latest value:
218270
Output
219271
min median mean max
220272
0 3 6.9 19
273+
274+
---
275+
276+
Code
277+
rs5$revision_behavior %>% print(n = 10, width = 300)
278+
Output
221279
# A tibble: 7 x 11
222280
time_value geo_value n_revisions min_lag max_lag lag_near_latest spread
223281
<dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>

tests/testthat/test-revision-latency-functions.R

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,36 @@ dummy_ex_integerly <- dummy_ex$DT %>%
6464
stopifnot(dummy_ex_integerly$time_type == "integer")
6565

6666
test_that("revision_summary works for dummy datasets", {
67-
expect_snapshot(dummy_ex %>% revision_summary() %>% print(n = 10, width = 300))
68-
expect_snapshot(dummy_ex %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300))
67+
rs1 <- dummy_ex %>% revision_summary()
68+
rs2 <- dummy_ex %>% revision_summary(drop_nas = FALSE)
69+
expect_snapshot(rs1)
70+
expect_snapshot(rs1$revision_behavior %>% print(n = 10, width = 300))
71+
expect_snapshot(rs2)
72+
expect_snapshot(rs2$revision_behavior %>% print(n = 10, width = 300))
6973

7074
# Weekly dummy is mostly just "day" -> "week", but quick-revision summary changes:
71-
expect_snapshot(dummy_ex_weekly %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300))
75+
rs3 <- dummy_ex_weekly %>% revision_summary(drop_nas = FALSE)
76+
expect_snapshot(rs3)
77+
expect_snapshot(rs3$revision_behavior %>% print(n = 10, width = 300))
7278
# Yearmonthly has the same story. It would have been close to encountering
7379
# min_waiting_period-based filtering but we actually set its versions_end to
7480
# sometime in 2080 rather than 2022:
75-
expect_snapshot(dummy_ex_yearmonthly %>% revision_summary(drop_nas = FALSE) %>% print(n = 10, width = 300))
81+
rs4 <- dummy_ex_yearmonthly %>% revision_summary(drop_nas = FALSE)
82+
expect_snapshot(rs4)
83+
expect_snapshot(rs4$revision_behavior %>% print(n = 10, width = 300))
7684
# Integer is very much like daily. We have to provide some of the
7785
# configuration arguments since we have no idea about what the integers
7886
# represent. If the possible integers being used have large jumps like
7987
# YYYYww-as-integer epiweek labels (e.g., 200053 jumps to 200101) or are
8088
# regularly spaced apart but by more than 1, we'll still be producing
8189
# something nonsensical, but we tried.
82-
expect_snapshot(dummy_ex_integerly %>%
90+
rs5 <- dummy_ex_integerly %>%
8391
revision_summary(
8492
min_waiting_period = 60, quick_revision = 3,
8593
drop_nas = FALSE
86-
) %>%
87-
print(n = 10, width = 300))
94+
)
95+
expect_snapshot(rs5)
96+
expect_snapshot(rs5$revision_behavior %>% print(n = 10, width = 300))
8897
})
8998

9099
test_that("tidyselect is functional", {
@@ -133,7 +142,7 @@ test_that("revision_summary default min_waiting_period works as expected", {
133142
value = 1:2
134143
) %>%
135144
as_epi_archive(versions_end = as.Date("2020-01-01") + 1 + 59) %>%
136-
revision_summary(print_inform = FALSE) %>%
145+
revision_summary(return_only_tibble = TRUE) %>%
137146
pull(time_value),
138147
as.Date("2020-01-01")
139148
)
@@ -146,7 +155,7 @@ test_that("revision_summary default min_waiting_period works as expected", {
146155
value = 1:2
147156
) %>%
148157
as_epi_archive(versions_end = as.Date("2020-01-01") + 7 + 56) %>%
149-
revision_summary(print_inform = FALSE) %>%
158+
revision_summary(return_only_tibble = TRUE) %>%
150159
pull(time_value),
151160
as.Date("2020-01-01")
152161
)
@@ -159,7 +168,7 @@ test_that("revision_summary default min_waiting_period works as expected", {
159168
value = 1:2
160169
) %>%
161170
as_epi_archive(versions_end = tsibble::make_yearmonth(2000, 3)) %>%
162-
revision_summary(print_inform = FALSE) %>%
171+
revision_summary(return_only_tibble = TRUE) %>%
163172
pull(time_value),
164173
tsibble::make_yearmonth(2000, 1)
165174
)
@@ -172,7 +181,7 @@ test_that("revision_summary default min_waiting_period works as expected", {
172181
value = 1:2
173182
) %>%
174183
as_epi_archive(versions_end = 1 + 1 + 59) %>%
175-
revision_summary(print_inform = FALSE),
184+
revision_summary(return_only_tibble = TRUE),
176185
regexp = "Unsupported time_type"
177186
)
178187
})

0 commit comments

Comments
 (0)