Skip to content

Commit

Permalink
test: unit tests for read_cpr_north_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 15, 2024
1 parent a8741bd commit 16d8949
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/testthat/test-read_cpr_north_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Data for tests ----

df <- data.frame("count_bin_min" = rep(1, 2),
"count_bin_max" = rep(1, 2))


## read_cpr_north_data() ----

test_that("Test read_cpr_north_data() for error", {

create_tempdir()

expect_error(read_cpr_north_data(version = "07"),
paste0("The directory './forcis-db/version-07' does not exist. ",
"Please check the argument 'path' or use the function ",
"'download_forcis_db()'."),
fixed = TRUE)

dir.create(file.path("forcis-db", "version-07"), recursive = TRUE)

expect_error(read_cpr_north_data(version = "07"),
paste0("The North CPR dataset does not exist. Please use the ",
"function 'download_forcis_db()'."),
fixed = TRUE)
})

test_that("Test read_cpr_north_data() for success", {

create_tempdir()

dir.create(file.path("forcis-db", "version-07"), recursive = TRUE)

write.csv2(df,
file = file.path("forcis-db", "version-07",
"FORCIS_cpr_north_test.csv"),
row.names = FALSE)

x <- read_cpr_north_data(version = "07", check_for_update = FALSE)

expect_equal(class(x), "data.frame")
expect_equal(ncol(x), 3L)
expect_equal(nrow(x), 2L)

expect_true("data_type" %in% colnames(x))
expect_true("CPR North" %in% x$"data_type")
})

0 comments on commit 16d8949

Please sign in to comment.