tests/testthat/test-get-constants.R

## get_names_series -----------------------------------------------------------

test_that("'get_names_series' works - args all FALSE", {
    expect_setequal(get_names_series(incl_popn = FALSE,
                                     incl_stock = FALSE,
                                     one_imem = FALSE,
                                     incl_internal = FALSE),
                    c("births",
                      "deaths",
                      "immigration1",
                      "emigration1",
                      "immigration2",
                      "emigration2"))
})

test_that("'get_names_series' works - args all TRUE except 'incl_stock'", {
    expect_setequal(get_names_series(incl_popn = TRUE,
                                     incl_stock = FALSE,
                                     one_imem = TRUE,
                                     incl_internal = TRUE),
                    c("population",
                      "births",
                      "deaths",
                      "immigration",
                      "emigration",
                      "internal_in",
                      "internal_out"))
})

test_that("'get_names_series' works - args all TRUE except 'incl_popn'", {
    expect_setequal(get_names_series(incl_popn = FALSE,
                                     incl_stock = TRUE,
                                     one_imem = TRUE,
                                     incl_internal = TRUE),
                    c("stock",
                      "births",
                      "deaths",
                      "immigration",
                      "emigration",
                      "internal_in",
                      "internal_out"))
})


## get_sets_names_series ------------------------------------------------------

test_that("'get_sets_names_series' works - incl_popn is FALSE, incl_stock is FALSE", {
    expect_setequal(get_sets_names_series(incl_popn = FALSE, incl_stock = FALSE),
                    list(c("births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2"),
                         c("births",
                           "deaths",
                           "immigration",
                           "emigration"),
                         c("births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2",
                           "internal_in",
                           "internal_out"),
                         c("births",
                           "deaths",
                           "immigration",
                           "emigration",
                           "internal_in",
                           "internal_out")))
})

test_that("'get_sets_names_series' works - incl_popn is TRUE, incl_stock = FALSE", {
    expect_setequal(get_sets_names_series(incl_popn = TRUE, incl_stock = FALSE),
                    list(c("population",
                           "births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2"),
                         c("population",
                           "births",
                           "deaths",
                           "immigration",
                           "emigration"),
                         c("population",
                           "births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2",
                           "internal_in",
                           "internal_out"),
                         c("population",
                           "births",
                           "deaths",
                           "immigration",
                           "emigration",
                           "internal_in",
                           "internal_out")))
})

test_that("'get_sets_names_series' works - incl_popn is FALSE, incl_stock = TRUE", {
    expect_setequal(get_sets_names_series(incl_popn = FALSE, incl_stock = TRUE),
                    list(c("stock",
                           "births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2"),
                         c("stock",
                           "births",
                           "deaths",
                           "immigration",
                           "emigration"),
                         c("stock",
                           "births",
                           "deaths",
                           "immigration1",
                           "emigration1",
                           "immigration2",
                           "emigration2",
                           "internal_in",
                           "internal_out"),
                         c("stock",
                           "births",
                           "deaths",
                           "immigration",
                           "emigration",
                           "internal_in",
                           "internal_out")))
})


## get_names_classif_vars -----------------------------------------------------

test_that("'get_names_classif_vars' works - arguments all FALSE", {
    expect_setequal(get_names_classif_vars(incl_cohort = FALSE,
                                           incl_sex = FALSE,
                                           incl_gender = FALSE,
                                           incl_region = FALSE),
                    c("age", "time"))
})

test_that("'get_names_classif_vars' works - arguments all TRUE except 'incl_gender'", {
    expect_setequal(get_names_classif_vars(incl_cohort = TRUE,
                                           incl_sex = TRUE,
                                           incl_gender = FALSE,
                                           incl_region = TRUE),
                    c("cohort", "sex", "age", "time", "region"))
})

test_that("'get_names_classif_vars' works - arguments all TRUE except 'incl_sex'", {
    expect_setequal(get_names_classif_vars(incl_cohort = TRUE,
                                           incl_sex = FALSE,
                                           incl_gender = TRUE,
                                           incl_region = TRUE),
                    c("cohort", "gender", "age", "time", "region"))
})


## get_sets_names_classif_vars -----------------------------------------------------

test_that("'get_sets_names_classif_vars' works - arguments all FALSE", {
    expect_setequal(get_sets_names_classif_vars(incl_cohort = FALSE,
                                                incl_sexgender = FALSE,
                                                incl_region = FALSE),
                    list(c("age", "time")))
})

test_that("'get_sets_names_classif_vars' works - arguments all TRUE", {
    expect_setequal(get_sets_names_classif_vars(incl_cohort = TRUE,
                                                incl_sexgender = TRUE,
                                                incl_region = TRUE),
                    list(c("age", "time", "cohort", "sex", "region"),
                         c("age", "time", "cohort", "gender", "region")))
})

test_that("'get_sets_names_classif_vars' works - arguments all NULL", {
    expect_setequal(get_sets_names_classif_vars(incl_cohort = NULL,
                                                incl_sexgender = NULL,
                                                incl_region = NULL),
                    list(c("age", "time"                              ),
                         c("age", "time", "cohort"                    ),
                         c("age", "time",           "sex"             ),
                         c("age", "time", "cohort", "sex"             ),
                         c("age", "time",                     "region"),
                         c("age", "time", "cohort",           "region"),
                         c("age", "time",           "sex",    "region"),
                         c("age", "time", "cohort", "sex",    "region"),
                         c("age", "time"                              ),
                         c("age", "time", "cohort"                    ),
                         c("age", "time",           "gender"          ),
                         c("age", "time", "cohort", "gender"          ),
                         c("age", "time",                     "region"),
                         c("age", "time", "cohort",           "region"),
                         c("age", "time",           "gender", "region"),
                         c("age", "time", "cohort", "gender", "region")))
})











## get_nms_series_cdms --------------------------------------------------------

test_that("'get_nms_series_cdms' gives expected values when data does not have 'region' variable", {
    nms_classif <- c("cohort", "age", "sex", "time", "count")
    expect_setequal(get_nms_series_cdms(nms_classif = nms_classif),
                    c("stock",
                      "immigration1",
                      "emigration1",
                      "immigration2",
                      "emigration2"))
})

test_that("'get_nms_series_cdms' gives expected values when data does have 'region' variable", {
    nms_classif <- c("cohort", "age", "sex", "time", "region", "count")
    expect_setequal(get_nms_series_cdms(nms_classif = nms_classif),
                    c("stock",
                      "immigration1",
                      "emigration1",
                      "immigration2",
                      "emigration2",
                      "internal_in",
                      "internal_out"))
})

    
ONSdigital/Bayesian-demographic-accounts documentation built on Jan. 10, 2022, 12:34 a.m.