diff --git a/tests/testthat/test-compute_abundances.R b/tests/testthat/test-compute_abundances.R new file mode 100644 index 0000000..f5c0301 --- /dev/null +++ b/tests/testthat/test-compute_abundances.R @@ -0,0 +1,37 @@ +## Data for test ---- + +df <- vroom::vroom(system.file(file.path("extdata", "FORCIS_pump_sample.csv"), + package = "forcis"), + delim = ";", altrep = FALSE, show_col_types = FALSE) + +df <- add_data_type(df, "Pump") +df <- select_taxonomy(df, "VT") + +df2 <- df +df2 <- add_data_type(df2, "CPR North") + + +## compute_abundances() ---- + +test_that("Test compute_abundances() for error", { + + expect_error(compute_abundances(df2), + paste0("This function is not designed to work with 'CPR North' ", + "or 'Sediment trap' data"), + fixed = TRUE) +}) + +test_that("Test compute_abundances() for success", { + + expect_message(res <- compute_abundances(df)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 69L) + expect_equal(nrow(res), 3024L) + + expect_message(res <- compute_abundances(df, aggregate = FALSE)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 72L) + expect_equal(nrow(res), 3024L) +}) diff --git a/tests/testthat/test-compute_concentrations.R b/tests/testthat/test-compute_concentrations.R new file mode 100644 index 0000000..eafe014 --- /dev/null +++ b/tests/testthat/test-compute_concentrations.R @@ -0,0 +1,49 @@ +## Data for test ---- + +df <- vroom::vroom(system.file(file.path("extdata", "FORCIS_pump_sample.csv"), + package = "forcis"), + delim = ";", altrep = FALSE, show_col_types = FALSE) + +df <- add_data_type(df, "Pump") +df <- select_taxonomy(df, "VT") + +df2 <- df +df2 <- add_data_type(df2, "Sediment trap") + +df3 <- vroom::vroom(system.file(file.path("extdata", "FORCIS_cpr_north_sample.csv"), + package = "forcis"), + delim = ";", altrep = FALSE, show_col_types = FALSE) + +df3 <- add_data_type(df3, "CPR North") + + +## compute_concentrations() ---- + +test_that("Test compute_concentrations() for error", { + + expect_error(compute_concentrations(df2), + paste0("This function is not designed to work with ", + "'Sediment trap' data"), + fixed = TRUE) +}) + +test_that("Test compute_concentrations() for success", { + + expect_message(res <- compute_concentrations(df)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 69L) + expect_equal(nrow(res), 3024L) + + expect_message(res <- compute_concentrations(df, aggregate = FALSE)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 72L) + expect_equal(nrow(res), 7280L) + + res <- compute_concentrations(df3) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 78L) + expect_equal(nrow(res), 440L) +}) diff --git a/tests/testthat/test-compute_frequencies.R b/tests/testthat/test-compute_frequencies.R new file mode 100644 index 0000000..2704daa --- /dev/null +++ b/tests/testthat/test-compute_frequencies.R @@ -0,0 +1,37 @@ +## Data for test ---- + +df <- vroom::vroom(system.file(file.path("extdata", "FORCIS_pump_sample.csv"), + package = "forcis"), + delim = ";", altrep = FALSE, show_col_types = FALSE) + +df <- add_data_type(df, "Pump") +df <- select_taxonomy(df, "VT") + +df2 <- df +df2 <- add_data_type(df2, "CPR North") + + +## compute_frequencies() ---- + +test_that("Test compute_frequencies() for error", { + + expect_error(compute_frequencies(df2), + paste0("This function is not designed to work with 'CPR North' ", + "or 'Sediment trap' data"), + fixed = TRUE) +}) + +test_that("Test compute_frequencies() for success", { + + expect_message(res <- compute_frequencies(df)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 68L) + expect_equal(nrow(res), 6832L) + + expect_message(res <- compute_frequencies(df, aggregate = FALSE)) + + expect_true(is.data.frame(res)) + expect_equal(ncol(res), 71L) + expect_equal(nrow(res), 6832L) +})