@@ -113,3 +113,47 @@ test_that("parse_api_date accepts YYYYMMDD and YYYY-MM-DD", {
113
113
test_that(" parse_api_date handles missing values appropriately" , {
114
114
expect_identical(parse_api_date(NA ), as.Date(NA ))
115
115
})
116
+
117
+ test_that(" date_to_epiweek accepts str and int input" , {
118
+ expect_identical(date_to_epiweek(" 20200101" ), 202001 )
119
+ expect_identical(date_to_epiweek(20200101 ), 202001 )
120
+ })
121
+
122
+ test_that(" date_to_epiweek accepts single and double-digit weeks" , {
123
+ expect_identical(date_to_epiweek(20201101 ), 202045 )
124
+ expect_identical(date_to_epiweek(20200109 ), 202002 )
125
+ })
126
+
127
+ test_that(" reformat_epirange works in basic cases" , {
128
+ # Week to week
129
+ result <- reformat_epirange(epirange(202002 , 202013 ), " week" )
130
+ expect_identical(result , epirange(202002 , 202013 ))
131
+
132
+ result <- reformat_epirange(epirange(" 202002" , " 202013" ), " week" )
133
+ expect_identical(result , epirange(" 202002" , " 202013" ))
134
+
135
+ # Week to day
136
+ # Across year boundary
137
+ result <- reformat_epirange(epirange(202001 , 202013 ), " day" )
138
+ expect_identical(result , epirange(20191229 , 20200322 ))
139
+
140
+ result <- reformat_epirange(epirange(202002 , 202013 ), " day" )
141
+ expect_identical(result , epirange(20200105 , 20200322 ))
142
+
143
+ result <- reformat_epirange(epirange(" 202002" , " 202013" ), " day" )
144
+ expect_identical(result , epirange(20200105 , 20200322 ))
145
+
146
+ # Day to week
147
+ result <- reformat_epirange(epirange(20200201 , 20201031 ), " week" )
148
+ expect_identical(result , epirange(202005 , 202044 ))
149
+
150
+ result <- reformat_epirange(epirange(" 20200201" , " 20201031" ), " week" )
151
+ expect_identical(result , epirange(202005 , 202044 ))
152
+
153
+ # Day to day
154
+ result <- reformat_epirange(epirange(20200201 , 20201031 ), " day" )
155
+ expect_identical(result , epirange(20200201 , 20201031 ))
156
+
157
+ result <- reformat_epirange(epirange(" 20200201" , " 20201031" ), " day" )
158
+ expect_identical(result , epirange(" 20200201" , " 20201031" ))
159
+ })
0 commit comments