Skip to content

Commit

Permalink
test: unit tests for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 13, 2024
1 parent 9dd9014 commit 1f739ee
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 16 deletions.
16 changes: 0 additions & 16 deletions tests/testthat/test-date_format.R

This file was deleted.

171 changes: 171 additions & 0 deletions tests/testthat/test-variables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
## date_format() ----

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

x <- date_format()

expect_equal(x, "%d/%m/%Y")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)

x <- as.Date("01/01/1900", date_format())

expect_equal(x, as.Date("1900-01-01"))
expect_equal(class(x), "Date")
expect_equal(length(x), 1L)
})



## cpr_north_filename() ----

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

x <- cpr_north_filename()

expect_equal(x, "FORCIS_cpr_north_")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## cpr_south_filename() ----

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

x <- cpr_south_filename()

expect_equal(x, "FORCIS_cpr_south_")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## plankton_net_filename() ----

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

x <- plankton_net_filename()

expect_equal(x, "FORCIS_net_")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## pump_filename() ----

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

x <- pump_filename()

expect_equal(x, "FORCIS_pump_")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## sediment_trap_filename() ----

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

x <- sediment_trap_filename()

expect_equal(x, "FORCIS_trap_")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## iho_oceans_filename() ----

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

x <- iho_oceans_filename()

expect_equal(x, "iho_oceans_boundaries")
expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## required_columns() ----

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

x <- required_columns()

expect_equal(x[1], "data_type")
expect_equal(class(x), "character")
expect_equal(length(x), 21L)
})



## data_types() ----

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

x <- data_types()

expect_true(all(c("Net", "Pump", "Sediment trap", "CPR South", "CPR North")
%in% x))

expect_equal(class(x), "character")
expect_equal(length(x), 5L)
})



## crs_robinson() ----

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

y <- paste0("+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 ",
"+units=m +no_defs")

x <- crs_robinson()

expect_equal(x, y)

expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## zen_record_id() ----

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

x <- zen_record_id()

expect_equal(x, "7390791")

expect_equal(class(x), "character")
expect_equal(length(x), 1L)
})



## species_list() ----

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

x <- species_list()

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

expect_equal(colnames(x)[1], "taxon")
expect_equal(colnames(x)[2], "taxonomy")

expect_true(all(c("LT", "VT", "OT","ZZ") %in% unique(x$"taxonomy")))
})

0 comments on commit 1f739ee

Please sign in to comment.