Commit | Line | Data |
---|---|---|
44a9990b | 1 | context("Check that date <--> integer indexes conversions work") |
1e20780e | 2 | |
44a9990b BA |
3 | ts_data = system.file("testdata","ts_test.csv",package="talweg") |
4 | exo_data = system.file("testdata","exo_test.csv",package="talweg") | |
5 | data0 <<- getData(ts_data, exo_data, input_tz="GMT", date_format="%Y-%m-%d %H:%M", | |
6 | working_tz="GMT", predict_at=0, limit=Inf) | |
7 | data7 <<- getData(ts_data, exo_data, input_tz="GMT", date_format="%Y-%m-%d %H:%M", | |
8 | working_tz="GMT", predict_at=7, limit=Inf) | |
9 | ||
10 | test_that("dateIndexToInteger, predict_at == 0", | |
11 | { | |
12 | expect_identical( dateIndexToInteger("2007-01-01",data0), 1 ) | |
13 | expect_identical( dateIndexToInteger("2007-01-02",data0), 2 ) | |
14 | expect_identical( dateIndexToInteger("2007-02-01",data0), 32 ) | |
15 | expect_identical( dateIndexToInteger("2007-03-01",data0), 60 ) | |
16 | expect_identical( dateIndexToInteger("2007-05-31",data0), 151 ) | |
17 | }) | |
18 | ||
19 | test_that("dateIndexToInteger, predict_at > 0", | |
20 | { | |
21 | expect_identical( dateIndexToInteger("2007-01-01",data7), 1 ) | |
22 | expect_identical( dateIndexToInteger("2007-01-02",data7), 3 ) | |
23 | expect_identical( dateIndexToInteger("2007-02-01",data7), 33 ) | |
24 | expect_identical( dateIndexToInteger("2007-03-01",data7), 61 ) | |
25 | expect_identical( dateIndexToInteger("2007-05-31",data7), 152 ) | |
26 | }) | |
27 | ||
28 | test_that("integerIndexToDate, predict_at == 0", | |
a65907cc | 29 | { |
44a9990b BA |
30 | expect_identical( integerIndexToDate( 1,data0), as.Date("2007-01-01") ) |
31 | expect_identical( integerIndexToDate( 2,data0), as.Date("2007-01-02") ) | |
32 | expect_identical( integerIndexToDate( 32,data0), as.Date("2007-02-01") ) | |
33 | expect_identical( integerIndexToDate( 60,data0), as.Date("2007-03-01") ) | |
34 | expect_identical( integerIndexToDate(151,data0), as.Date("2007-05-31") ) | |
a65907cc | 35 | }) |
6d97bfec | 36 | |
44a9990b | 37 | test_that("integerIndexToDate, predict_at > 0", |
6d97bfec | 38 | { |
44a9990b BA |
39 | expect_identical( integerIndexToDate( 1,data7), as.Date("2007-01-01") ) |
40 | expect_identical( integerIndexToDate( 2,data7), as.Date("2007-01-01") ) | |
41 | expect_identical( integerIndexToDate( 3,data7), as.Date("2007-01-02") ) | |
42 | expect_identical( integerIndexToDate( 33,data7), as.Date("2007-02-01") ) | |
43 | expect_identical( integerIndexToDate( 61,data7), as.Date("2007-03-01") ) | |
44 | expect_identical( integerIndexToDate(152,data7), as.Date("2007-05-31") ) | |
45 | }) | |
46 | ||
47 | test_that("dateIndexToInteger(integerIndexToDate) == Id", | |
48 | { | |
49 | #always true except for second cell when predict_at>0: same date | |
50 | expect_identical( dateIndexToInteger(integerIndexToDate( 1,data0),data0), 1 ) | |
51 | expect_identical( dateIndexToInteger(integerIndexToDate( 1,data7),data7), 1 ) | |
52 | expect_identical( dateIndexToInteger(integerIndexToDate( 2,data0),data0), 2 ) | |
53 | expect_identical( dateIndexToInteger(integerIndexToDate( 2,data7),data7), 1 ) | |
54 | expect_identical( dateIndexToInteger(integerIndexToDate( 32,data0),data0), 32 ) | |
55 | expect_identical( dateIndexToInteger(integerIndexToDate( 32,data7),data7), 32 ) | |
56 | expect_identical( dateIndexToInteger(integerIndexToDate( 60,data0),data0), 60 ) | |
57 | expect_identical( dateIndexToInteger(integerIndexToDate( 60,data7),data7), 60 ) | |
58 | expect_identical( dateIndexToInteger(integerIndexToDate(151,data0),data0), 151 ) | |
59 | expect_identical( dateIndexToInteger(integerIndexToDate(151,data7),data7), 151 ) | |
60 | }) | |
61 | ||
62 | test_that("integerIndexToDate(dateIndexToInteger) == Id", | |
63 | { | |
64 | expect_identical( | |
65 | integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0), as.Date("2007-01-01") ) | |
66 | expect_identical( | |
67 | integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7), as.Date("2007-01-01") ) | |
68 | expect_identical( | |
69 | integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0), as.Date("2007-01-02") ) | |
70 | expect_identical( | |
71 | integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7), as.Date("2007-01-02") ) | |
72 | expect_identical( | |
73 | integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") ) | |
74 | expect_identical( | |
75 | integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") ) | |
76 | expect_identical( | |
77 | integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") ) | |
78 | expect_identical( | |
79 | integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") ) | |
80 | expect_identical( | |
81 | integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") ) | |
82 | expect_identical( | |
83 | integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") ) | |
84 | }) |