- data7 = getData(ts_data="pm10_mesures_H_loc.csv", exo_data="meteo_extra_noNAs.csv",
- input_tz="Europe/Paris",working_tz="Europe/Paris", predict_at=7, limit=200)
- expect_identical( dateIndexToInteger("2008-12-10",data), 2 )
- expect_identical( dateIndexToInteger("2008-12-11",data), 3 )
- expect_identical( dateIndexToInteger("2008-12-20",data), 12 )
- expect_identical( dateIndexToInteger("2009-02-01",data), 54 )
- expect_identical( dateIndexToInteger("2009-03-01",data), 82 )
- expect_identical( dateIndexToInteger("2009-05-31",data), 173 )
-}
+ expect_identical( integerIndexToDate( 1,data7), as.Date("2007-01-01") )
+ expect_identical( integerIndexToDate( 2,data7), as.Date("2007-01-01") )
+ expect_identical( integerIndexToDate( 3,data7), as.Date("2007-01-02") )
+ expect_identical( integerIndexToDate( 33,data7), as.Date("2007-02-01") )
+ expect_identical( integerIndexToDate( 61,data7), as.Date("2007-03-01") )
+ expect_identical( integerIndexToDate(152,data7), as.Date("2007-05-31") )
+})
+
+test_that("dateIndexToInteger(integerIndexToDate) == Id",
+{
+ #always true except for second cell when predict_at>0: same date
+ expect_identical( dateIndexToInteger(integerIndexToDate( 1,data0),data0), 1 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 1,data7),data7), 1 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 2,data0),data0), 2 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 2,data7),data7), 1 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 32,data0),data0), 32 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 32,data7),data7), 32 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 60,data0),data0), 60 )
+ expect_identical( dateIndexToInteger(integerIndexToDate( 60,data7),data7), 60 )
+ expect_identical( dateIndexToInteger(integerIndexToDate(151,data0),data0), 151 )
+ expect_identical( dateIndexToInteger(integerIndexToDate(151,data7),data7), 151 )
+})
+
+test_that("integerIndexToDate(dateIndexToInteger) == Id",
+{
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-01-01",data0),data0), as.Date("2007-01-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-01-01",data7),data7), as.Date("2007-01-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-01-02",data0),data0), as.Date("2007-01-02") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-01-02",data7),data7), as.Date("2007-01-02") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-02-01",data0),data0), as.Date("2007-02-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-03-01",data0),data0), as.Date("2007-03-01") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
+ expect_identical(
+ integerIndexToDate(dateIndexToInteger("2007-05-31",data0),data0), as.Date("2007-05-31") )
+})