|
1 |
| -context("dst_date_parse") |
2 |
| - |
3 | 1 | test_that("dst_date_parse gives the correct class.", {
|
4 |
| - |
| 2 | + |
5 | 3 | exp_dates <- c("POSIXct", "POSIXt")
|
6 |
| - |
| 4 | + |
7 | 5 | # Daily
|
8 | 6 | expect_equal(class(dst_date_parse(dst_date = "2000M01D01")), exp_dates)
|
9 | 7 | expect_equal(class(dst_date_parse(dst_date = c("2000M01D20", "2000M02D21", "2000M03D23", "2000M04D24"))), exp_dates)
|
10 |
| - |
| 8 | + |
11 | 9 | # Monthly
|
12 | 10 | expect_equal(class(dst_date_parse(dst_date = "2000M01")), exp_dates)
|
13 | 11 | expect_equal(class(dst_date_parse(dst_date = c("2000M01", "2000M02", "2000M03", "2000M04", "2000M10", "2000M11"))), exp_dates)
|
14 |
| - |
| 12 | + |
15 | 13 | # Quarterly
|
16 | 14 | expect_equal(class(dst_date_parse(dst_date = "2000Q1")), exp_dates)
|
17 | 15 | expect_equal(class(dst_date_parse(dst_date = "2000Q2")), exp_dates)
|
18 | 16 | expect_equal(class(dst_date_parse(dst_date = "2000Q3")), exp_dates)
|
19 | 17 | expect_equal(class(dst_date_parse(dst_date = "2000Q4")), exp_dates)
|
20 | 18 | expect_equal(class(dst_date_parse(dst_date = c("2000Q1", "2000Q2", "2000Q3", "2000Q4"))), exp_dates)
|
21 |
| - |
| 19 | + |
22 | 20 | # Yearly
|
23 | 21 | expect_equal(class(dst_date_parse(dst_date = "2000")), exp_dates)
|
24 | 22 | expect_equal(class(dst_date_parse(dst_date = c("2000", "2000", "2000", "2000"))), exp_dates)
|
25 |
| - |
| 23 | + |
26 | 24 | expect_equal(class(dst_date_parse(dst_date = c("2015H1", "2015H2"))), exp_dates)
|
27 | 25 | expect_equal(as.character(dst_date_parse(dst_date = c("2015H1", "2015H2"))), c("2015-01-01", "2015-07-01"))
|
28 |
| - |
| 26 | + |
29 | 27 | })
|
30 | 28 |
|
31 | 29 |
|
32 | 30 | test_that("Test that dst_date_parse stops when the input is bad.", {
|
33 |
| - |
| 31 | + |
34 | 32 | # Daily
|
35 | 33 | expect_error(dst_date_parse(dst_date = "2000M01D35"))
|
36 | 34 | expect_error(dst_date_parse(dst_date = "2000M10D40"))
|
37 |
| - |
| 35 | + |
38 | 36 | # Monthly
|
39 | 37 | expect_error(dst_date_parse(dst_date = "20000M01"))
|
40 | 38 | expect_error(dst_date_parse(dst_date = "2000M101"))
|
41 | 39 | expect_error(dst_date_parse(dst_date = "2000M13"))
|
42 |
| - |
| 40 | + |
43 | 41 | # Quarterly
|
44 | 42 | expect_error(dst_date_parse(dst_date = "2000Q0"))
|
45 | 43 | expect_error(dst_date_parse(dst_date = "2000Q5"))
|
46 |
| - |
| 44 | + |
47 | 45 | # Yearly
|
48 | 46 | expect_error(dst_date_parse(dst_date = "20000"))
|
49 | 47 | expect_error(dst_date_parse(dst_date = "200"))
|
50 |
| - |
| 48 | + |
51 | 49 | })
|
0 commit comments