a few simplifications in computeFilaments, prepare markdown report
[talweg.git] / pkg / tests / testthat / test.dateIndexToInteger.R
CommitLineData
44a9990b 1context("Check that date <--> integer indexes conversions work")
1e20780e 2
44a9990b
BA
3ts_data = system.file("testdata","ts_test.csv",package="talweg")
4exo_data = system.file("testdata","exo_test.csv",package="talweg")
5data0 <<- getData(ts_data, exo_data, input_tz="GMT", date_format="%Y-%m-%d %H:%M",
6 working_tz="GMT", predict_at=0, limit=Inf)
7data7 <<- 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
af3b84f4 10test_that("dateIndexToInteger",
44a9990b
BA
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 )
44a9990b 17
44a9990b 18 expect_identical( dateIndexToInteger("2007-01-01",data7), 1 )
af3b84f4
BA
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 )
44a9990b
BA
23})
24
af3b84f4 25test_that("integerIndexToDate",
a65907cc 26{
44a9990b
BA
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") )
6d97bfec 32
44a9990b 33 expect_identical( integerIndexToDate( 1,data7), as.Date("2007-01-01") )
af3b84f4
BA
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") )
44a9990b
BA
38})
39
40test_that("dateIndexToInteger(integerIndexToDate) == Id",
41{
44a9990b
BA
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 )
af3b84f4 45 expect_identical( dateIndexToInteger(integerIndexToDate( 2,data7),data7), 2 )
44a9990b
BA
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 )
52})
53
54test_that("integerIndexToDate(dateIndexToInteger) == Id",
55{
56 expect_identical(
57 integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0), as.Date("2007-01-01") )
58 expect_identical(
59 integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7), as.Date("2007-01-01") )
60 expect_identical(
61 integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0), as.Date("2007-01-02") )
62 expect_identical(
63 integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7), as.Date("2007-01-02") )
64 expect_identical(
65 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
66 expect_identical(
67 integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
68 expect_identical(
69 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
70 expect_identical(
71 integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
72 expect_identical(
73 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
74 expect_identical(
75 integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
76})