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",
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 )
18 expect_identical( dateIndexToInteger("2007-01-01",data7), 1 )
19 expect_identical( dateIndexToInteger("2007-01-02",data7), 2 )
20 expect_identical( dateIndexToInteger("2007-02-01",data7), 32 )
21 expect_identical( dateIndexToInteger("2007-03-01",data7), 60 )
22 expect_identical( dateIndexToInteger("2007-05-31",data7), 151 )
25 test_that("integerIndexToDate",
27 expect_identical( integerIndexToDate( 1,data0), as.Date("2007-01-01") )
28 expect_identical( integerIndexToDate( 2,data0), as.Date("2007-01-02") )
29 expect_identical( integerIndexToDate( 32,data0), as.Date("2007-02-01") )
30 expect_identical( integerIndexToDate( 60,data0), as.Date("2007-03-01") )
31 expect_identical( integerIndexToDate(151,data0), as.Date("2007-05-31") )
33 expect_identical( integerIndexToDate( 1,data7), as.Date("2007-01-01") )
34 expect_identical( integerIndexToDate( 2,data7), as.Date("2007-01-02") )
35 expect_identical( integerIndexToDate( 32,data7), as.Date("2007-02-01") )
36 expect_identical( integerIndexToDate( 60,data7), as.Date("2007-03-01") )
37 expect_identical( integerIndexToDate(151,data7), as.Date("2007-05-31") )
40 test_that("dateIndexToInteger(integerIndexToDate) == Id",
42 expect_identical( dateIndexToInteger(integerIndexToDate( 1,data0),data0), 1 )
43 expect_identical( dateIndexToInteger(integerIndexToDate( 1,data7),data7), 1 )
44 expect_identical( dateIndexToInteger(integerIndexToDate( 2,data0),data0), 2 )
45 expect_identical( dateIndexToInteger(integerIndexToDate( 2,data7),data7), 2 )
46 expect_identical( dateIndexToInteger(integerIndexToDate( 32,data0),data0), 32 )
47 expect_identical( dateIndexToInteger(integerIndexToDate( 32,data7),data7), 32 )
48 expect_identical( dateIndexToInteger(integerIndexToDate( 60,data0),data0), 60 )
49 expect_identical( dateIndexToInteger(integerIndexToDate( 60,data7),data7), 60 )
50 expect_identical( dateIndexToInteger(integerIndexToDate(151,data0),data0), 151 )
51 expect_identical( dateIndexToInteger(integerIndexToDate(151,data7),data7), 151 )
54 test_that("integerIndexToDate(dateIndexToInteger) == Id",
57 integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0), as.Date("2007-01-01") )
59 integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7), as.Date("2007-01-01") )
61 integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0), as.Date("2007-01-02") )
63 integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7), as.Date("2007-01-02") )
65 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
67 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
69 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
71 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
73 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
75 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )