-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Data for tests ---- | ||
|
||
df_w <- data.frame("data_type" = rep("Net", 3), | ||
"column" = 1:3) | ||
|
||
df_wo <- data.frame("column" = 1:3) | ||
|
||
|
||
## add_data_type() ---- | ||
|
||
test_that("Test add_data_type() for success", { | ||
|
||
df <- add_data_type(df_w, "Net") | ||
|
||
expect_true(is.data.frame(df)) | ||
expect_true(class(df[ , 1]) == "character") | ||
|
||
expect_equal(ncol(df), 2L) | ||
expect_equal(nrow(df), 3L) | ||
|
||
expect_equal(unique(df[ , 1]), "Net") | ||
|
||
df <- add_data_type(df_w, "Pump") | ||
|
||
expect_true(is.data.frame(df)) | ||
expect_true(class(df[ , 1]) == "character") | ||
|
||
expect_equal(ncol(df), 2L) | ||
expect_equal(nrow(df), 3L) | ||
|
||
expect_equal(unique(df[ , 1]), "Pump") | ||
|
||
df <- add_data_type(df_wo, "Pump") | ||
|
||
expect_true(is.data.frame(df)) | ||
expect_true(class(df[ , 1]) == "character") | ||
|
||
expect_equal(ncol(df), 2L) | ||
expect_equal(nrow(df), 3L) | ||
|
||
expect_equal(unique(df[ , 1]), "Pump") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## Data for tests ---- | ||
|
||
df_g <- data.frame("data_type" = rep("Net", 3), | ||
"column" = 1:3) | ||
|
||
df_w <- data.frame("data_type" = c("Net", "Net", "Pump"), | ||
"column" = 1:3) | ||
|
||
|
||
## get_data_type() ---- | ||
|
||
test_that("Test get_data_type() for error", { | ||
|
||
expect_error(get_data_type(df_w), | ||
"The column 'data_type' cannot contain different values", | ||
fixed = TRUE) | ||
}) | ||
|
||
test_that("Test get_data_type() for success", { | ||
|
||
dt <- get_data_type(df_g) | ||
|
||
expect_true(is.character(dt)) | ||
expect_equal(length(dt), 1L) | ||
expect_equal(dt, "Net") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## get_ocean_names() ---- | ||
|
||
test_that("Test get_ocean_names() for success", { | ||
|
||
oceans <- get_ocean_names() | ||
|
||
expect_true(class(oceans) == "character") | ||
expect_true(length(oceans) == 8L) | ||
|
||
expect_equal(oceans[1], "Arctic Ocean") | ||
expect_equal(oceans[2], "Indian Ocean") | ||
expect_equal(oceans[3], "Mediterranean Sea") | ||
expect_equal(oceans[4], "North Atlantic Ocean") | ||
expect_equal(oceans[5], "North Pacific Ocean") | ||
expect_equal(oceans[6], "South Atlantic Ocean") | ||
expect_equal(oceans[7], "South Pacific Ocean") | ||
expect_equal(oceans[8], "Southern Ocean") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## Data for tests ---- | ||
|
||
df_cpr <- data.frame("data_type" = rep("CPR North", 5), | ||
"species" = c("n_pachyderma", "n_pachyderma", | ||
"conglobatus", "g_rubescens", | ||
"g_rubescens")) | ||
|
||
df_net <- data.frame("data_type" = rep("Net", 5), | ||
"n_pachyderma" = c(1:5), | ||
"conglobatus" = c(1:5), | ||
"g_rubescens" = c(1:5)) | ||
|
||
|
||
## get_species_names() ---- | ||
|
||
test_that("Test get_species_names() for success", { | ||
|
||
species <- get_species_names(df_cpr) | ||
|
||
expect_true(class(species) == "character") | ||
expect_true(length(species) == 3L) | ||
|
||
expect_equal(species[1], "n_pachyderma") | ||
expect_equal(species[2], "conglobatus") | ||
expect_equal(species[3], "g_rubescens") | ||
|
||
species <- get_species_names(df_net) | ||
|
||
expect_true(class(species) == "character") | ||
expect_true(length(species) == 3L) | ||
|
||
expect_equal(species[1], "n_pachyderma") | ||
expect_equal(species[2], "conglobatus") | ||
expect_equal(species[3], "g_rubescens") | ||
}) |