1 context("Check that date <--> integer indexes conversions work")
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)
10 test_that("dateIndexToInteger, predict_at == 0",
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 )
19 test_that("dateIndexToInteger, predict_at > 0",
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 )
28 test_that("integerIndexToDate, predict_at == 0",
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") )
37 test_that("integerIndexToDate, predict_at > 0",
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") )
47 test_that("dateIndexToInteger(integerIndexToDate) == Id",
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 )
62 test_that("integerIndexToDate(dateIndexToInteger) == Id",
65 integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0), as.Date("2007-01-01") )
67 integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7), as.Date("2007-01-01") )
69 integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0), as.Date("2007-01-02") )
71 integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7), as.Date("2007-01-02") )
73 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
75 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
77 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
79 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
81 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
83 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )