Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan committed Jan 21, 2025
1 parent 41da2a1 commit e4b6bfb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/testthat/test-get_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,22 @@ test_that("errors on invalid filters", {
regexp = "col_select: invalid value"
)
})

test_that("We can filter data with `Sex = 'All'`", {
pops <- get_resource(
res_id = "27a72cc8-d6d8-430c-8b4f-3109a9ceadb1",
row_filters = list("Sex" = "All"),
col_select = c("Year", "HB", "AllAges", "Sex")
)

expect_s3_class(pops, "tbl_df")
expect_equal(nrow(pops), 645)
expect_named(pops, c(
"Year",
"HB",
"AllAges",
"Sex"
))
expect_length(unique(pops$HB), 15)
expect_setequal(pops$Sex, "All")
})
17 changes: 17 additions & 0 deletions tests/testthat/test-parse_row_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ test_that("returns FALSE for length > 1", {
)
})

test_that("returns FALSE if `Sex = 'All'` is given", {
expect_false(
parse_row_filters(list("Sex" = "All"))
)

expect_false(
parse_row_filters(list("Sex" = c("Male", "All")))
)

expect_false(
parse_row_filters(list(
"Sex" = "All",
"HBT" = "S1234"
))
)
})

test_that("throws error when un-named", {
expect_error(
parse_row_filters(list(1, 2)),
Expand Down

0 comments on commit e4b6bfb

Please sign in to comment.