Skip to content

Commit 088cb18

Browse files
committed
Improve test naming and comments
1 parent bd61fd3 commit 088cb18

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

R-packages/covidcast/tests/testthat/test-cor.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
library(covidcast)
22
library(tibble)
33

4-
test_that("simple correlations", {
4+
test_that("correlations when correlation is 1", {
55
# Two data frames with perfect correlation, except on a day that does not
6-
# match between the two of them
6+
# match between the two of them. The non-matching day does not have perfect
7+
# correlation, so this will detect if it is correctly excluded.
78
foo <- data.frame(
89
time_value = as.Date(c("2020-01-01", "2020-01-02",
910
"2020-01-03", "2020-01-05")),
@@ -30,7 +31,7 @@ test_that("simple correlations", {
3031
expected)
3132
})
3233

33-
test_that("basic lagged correlations", {
34+
test_that("lags are applied before correlating", {
3435
foo <- data.frame(
3536
time_value = as.Date(c("2020-01-01", "2020-01-02",
3637
"2020-01-03", "2020-01-04")),
@@ -57,7 +58,7 @@ test_that("basic lagged correlations", {
5758
expected)
5859
})
5960

60-
test_that("lags are in correct direction", {
61+
test_that("lags are applied in correct temporal direction", {
6162
foo <- data.frame(
6263
time_value = seq.Date(as.Date("2020-01-01"), as.Date("2020-01-10"),
6364
"day"),
@@ -74,6 +75,7 @@ test_that("lags are in correct direction", {
7475
value = c(rep(0, 5), 1:5)
7576
)
7677

78+
# These data frames have correlation 1 only if lagged exactly the right amount
7779
expected <- tibble(
7880
geo_value = "pa",
7981
value = 1

R-packages/covidcast/tests/testthat/test-covidcast.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
library(covidcast)
22
library(mockery)
33

4-
test_that("covidcast_meta", {
4+
test_that("covidcast_meta formats result correctly", {
55
stub(covidcast_meta, ".request",
66
list(message = "success",
77
epidata = data.frame(
88
min_time = c("20200101", "20201002"),
99
max_time = c("20200102", "20201003"),
1010
max_issue = c("20200404", "20201101"))))
1111

12+
# ensure columns that should be converted to dates are indeed dates
1213
expect_equal(covidcast_meta(),
1314
structure(
1415
data.frame(
@@ -19,6 +20,9 @@ test_that("covidcast_meta", {
1920
class = c("covidcast_meta", "data.frame")
2021
))
2122

23+
})
24+
25+
test_that("covidcast_meta raises error when API signals one", {
2226
stub(covidcast_meta, ".request",
2327
list(message = "argle-bargle"))
2428

R-packages/covidcast/tests/testthat/test-plot.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ library(testthat)
22
library(vdiffr)
33
library(dplyr)
44

5+
## Plotting tests.
6+
# Since it is difficult to test specific output of plots, these tests instead
7+
# use vdiffr to ensure that plots match a saved reference version. The tests
8+
# below simple build simple graphs of each type, thus exercising the different
9+
# plotting options and ensuring they all function.
10+
11+
512
# Contexts are no longer required or recommended in testthat, but vdiffr still
613
# wants one to place the figure files correctly. See
714
# https://github.com/r-lib/vdiffr/issues/71

0 commit comments

Comments
 (0)