1 context("Date <--> integer conversions")
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, date_format="%Y-%m-%d %H:%M", limit=Inf)
6 data7 <<- getData(ts_data, exo_data, date_format="%Y-%m-%d %H:%M", limit=Inf)
8 test_that("dateIndexToInteger works as expected",
10 expect_identical( dateIndexToInteger("2007-01-01",data0), 1 )
11 expect_identical( dateIndexToInteger("2007-01-02",data0), 2 )
12 expect_identical( dateIndexToInteger("2007-02-01",data0), 32 )
13 expect_identical( dateIndexToInteger("2007-03-01",data0), 60 )
14 expect_identical( dateIndexToInteger("2007-05-31",data0), 151 )
16 expect_identical( dateIndexToInteger("2007-01-01",data7), 1 )
17 expect_identical( dateIndexToInteger("2007-01-02",data7), 2 )
18 expect_identical( dateIndexToInteger("2007-02-01",data7), 32 )
19 expect_identical( dateIndexToInteger("2007-03-01",data7), 60 )
20 expect_identical( dateIndexToInteger("2007-05-31",data7), 151 )
23 test_that("integerIndexToDate works as expected",
25 expect_identical( integerIndexToDate( 1,data0), as.Date("2007-01-01") )
26 expect_identical( integerIndexToDate( 2,data0), as.Date("2007-01-02") )
27 expect_identical( integerIndexToDate( 32,data0), as.Date("2007-02-01") )
28 expect_identical( integerIndexToDate( 60,data0), as.Date("2007-03-01") )
29 expect_identical( integerIndexToDate(151,data0), as.Date("2007-05-31") )
31 expect_identical( integerIndexToDate( 1,data7), as.Date("2007-01-01") )
32 expect_identical( integerIndexToDate( 2,data7), as.Date("2007-01-02") )
33 expect_identical( integerIndexToDate( 32,data7), as.Date("2007-02-01") )
34 expect_identical( integerIndexToDate( 60,data7), as.Date("2007-03-01") )
35 expect_identical( integerIndexToDate(151,data7), as.Date("2007-05-31") )
38 test_that("dateIndexToInteger(integerIndexToDate) == Id",
40 expect_identical( dateIndexToInteger(integerIndexToDate( 1,data0),data0), 1 )
41 expect_identical( dateIndexToInteger(integerIndexToDate( 1,data7),data7), 1 )
42 expect_identical( dateIndexToInteger(integerIndexToDate( 2,data0),data0), 2 )
43 expect_identical( dateIndexToInteger(integerIndexToDate( 2,data7),data7), 2 )
44 expect_identical( dateIndexToInteger(integerIndexToDate( 32,data0),data0), 32 )
45 expect_identical( dateIndexToInteger(integerIndexToDate( 32,data7),data7), 32 )
46 expect_identical( dateIndexToInteger(integerIndexToDate( 60,data0),data0), 60 )
47 expect_identical( dateIndexToInteger(integerIndexToDate( 60,data7),data7), 60 )
48 expect_identical( dateIndexToInteger(integerIndexToDate(151,data0),data0), 151 )
49 expect_identical( dateIndexToInteger(integerIndexToDate(151,data7),data7), 151 )
52 test_that("integerIndexToDate(dateIndexToInteger) == Id",
54 expect_identical(integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0),
55 as.Date("2007-01-01") )
56 expect_identical(integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7),
57 as.Date("2007-01-01") )
58 expect_identical(integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0),
59 as.Date("2007-01-02") )
60 expect_identical(integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7),
61 as.Date("2007-01-02") )
62 expect_identical(integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0),
63 as.Date("2007-02-01") )
64 expect_identical(integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0),
65 as.Date("2007-02-01") )
66 expect_identical(integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0),
67 as.Date("2007-03-01") )
68 expect_identical(integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0),
69 as.Date("2007-03-01") )
70 expect_identical(integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0),
71 as.Date("2007-05-31") )
72 expect_identical(integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0),
73 as.Date("2007-05-31") )