tests/testthat/test-qdate.R

context("QDate")

test.date <- structure(c(1210204800, 1213401600, 1213574400, 1211068800, 1234742400,
            1211241600, 1223942400, 1211241600, 1223942400, 1218153600, 1217980800,
            1231372800, 1234656000, 1219104000, 1236988800, 1215129600, 1220572800,
            1213488000, 1240012800, 1211155200, 1223683200, 1212537600, 1231372800,
            1236124800, 1238544000, 1219017600, 1215820800, 1240272000, 1215993600,
            1238716800, 1215993600, 1236211200, 1211155200, 1238716800, 1215993600,
            1228521600, 1210982400, 1214956800, 1240099200, 1232409600, 1213660800,
            1234828800, 1223683200, 1218931200, 1231286400, 1215043200, 1234742400,
            1231459200, 1223856000, 1233792000, 1232323200, 1232323200, 1218153600,
            1210118400, 1210118400, 1218844800, 1213488000, 1219017600, 1234569600,
            1231459200, 1238716800, 1213574400, 1211068800, 1210982400, 1232236800,
            1219017600, 1226707200, 1211241600, 1220572800, 1223683200, 1231459200,
            1228521600, 1238544000, 1234569600, 1228521600, 1234656000, 1226880000,
            1223942400, 1220400000, 1210204800, 1233705600, 1228780800, 1231286400,
            1240185600, 1232150400, 1226707200, 1232323200, 1228521600, 1214956800,
            1215907200, 1212624000, 1228521600, 1233878400, 1213401600, 1228521600,
            1232150400, 1237248000, 1237248000, 1228521600, 1240272000),
          class = c("POSIXct","POSIXt", "QDate"),
          QDate = structure(c(1L, 2L, 2L, 1L, 10L, 1L, 6L, 1L, 6L, 4L, 4L, 9L, 10L, 4L, 11L, 3L, 5L, 2L, 12L, 1L,
                              6L, 2L, 9L, 11L, 12L, 4L, 3L, 12L, 3L, 12L, 3L, 11L, 1L, 12L,
                              3L, 8L, 1L, 3L, 12L, 9L, 2L, 10L, 6L, 4L, 9L, 3L, 10L, 9L, 6L,
                              10L, 9L, 9L, 4L, 1L, 1L, 4L, 2L, 4L, 10L, 9L, 12L, 2L, 1L, 1L,
                              9L, 4L, 7L, 1L, 5L, 6L, 9L, 8L, 12L, 10L, 8L, 10L, 7L, 6L, 5L,
                              1L, 10L, 8L, 9L, 12L, 9L, 7L, 9L, 8L, 3L, 3L, 2L, 8L, 10L, 2L,
                              8L, 9L, 11L, 11L, 8L, 12L), class = c("ordered", "factor"),
                            .Label = c("May 2008", "June 2008", "July 2008", "August 2008",
                                       "September 2008", "October 2008", "November 2008",
                                       "December 2008", "January 2009", "February 2009",
                                       "March 2009", "April 2009")),
          questiontype = "Date", name = "date", label = "Date", question = "Date")

test_that("Factor", {
    test.factor <- Factor(test.date)
    expect_equal(levels(test.factor), levels(attr(test.date, "QDate")))
    expect_equal(attr(test.factor, "name"), attr(test.date, "name"))
})

test_that("Ordered", {
    test.factor <- Ordered(test.date)
    expect_equal(levels(test.factor), levels(attr(test.date, "QDate")))
    expect_equal(attr(test.factor, "name"), attr(test.date, "name"))
})
NumbersInternational/flipTransformations documentation built on Feb. 26, 2024, 6:43 a.m.