reconhub / aweek

Convert dates to arbitrary week definitions :calendar:
https://www.repidemicsconsortium.org/aweek
Other
17 stars 4 forks source link

Fix incorrect test #35

Closed zkamvar closed 3 years ago

zkamvar commented 3 years ago

Problem

A single test is currently failing on CRAN and will continue to fail for the rest of the year until I fix it:

Version: 1.0.1
Check: tests
Result: ERROR
     Running 'spelling.R' [0s/0s]
     Running 'testthat.R' [2s/3s]
    Running the tests in 'tests/testthat.R' failed.
    Complete output:
     > library(testthat)
     > library(aweek)
     >
     > test_check("aweek")
     == Failed tests ================================================================
     -- Failure (test-make_aweek.R:22:3): get_aweek() will always default to the first weekday of the year --
     `d1` not identical to `d2`.
     Mean relative difference: 0.0003757179

     [ FAIL 1 | WARN 0 | SKIP 0 | PASS 193 ]
     Error: Test failures
     Execution halted
Flavor: r-devel-linux-x86_64-debian-clang

Code Causing the Problem

The following code incorrectly assumes that 1 January will land in the first week of the year, which is not the case for 2021 since 2020 had 53 weeks

aweek::date2week("2021-01-01")
#> <aweek start: Monday>
#> [1] "2020-W53-5"

Created on 2021-01-02 by the reprex package (v0.3.0)

https://github.com/reconhub/aweek/blob/bafde34e1ad8ab13706df637c973c6d1c80a6fab/tests/testthat/test-make_aweek.R#L18-L24

Solution