Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test strictness #276

Merged
merged 16 commits into from
Feb 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
swap expect_equal() for expect_identical(), declare explicit integers…
… in comparisons
PietrH committed Feb 3, 2023
commit a51eae887fae51856a214200323bf3ffc66a8e83
16 changes: 8 additions & 8 deletions tests/testthat/test-get_animal_projects.R
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ test_that("get_animal_projects() returns a tibble", {

test_that("get_animal_projects() returns unique project_id", {
df <- get_animal_projects(con)
expect_equal(nrow(df), nrow(df %>% distinct(project_id)))
expect_identical(nrow(df), nrow(df %>% distinct(project_id)))
})

test_that("get_animal_projects() returns the expected columns", {
@@ -36,7 +36,7 @@ test_that("get_animal_projects() returns the expected columns", {
"moratorium",
"imis_dataset_id"
)
expect_equal(names(df), expected_col_names)
expect_identical(names(df), expected_col_names)
})

test_that("get_animal_projects() allows selecting on animal_project_code", {
@@ -47,30 +47,30 @@ test_that("get_animal_projects() allows selecting on animal_project_code", {
# Select single value
single_select <- "2014_demer"
single_select_df <- get_animal_projects(con, animal_project_code = single_select)
expect_equal(
expect_identical(
single_select_df %>% distinct(project_code) %>% pull(),
c(single_select)
)
expect_equal(nrow(single_select_df), 1)
expect_identical(nrow(single_select_df), 1L)

# Selection is case insensitive
expect_equal(
expect_identical(
get_animal_projects(con, animal_project_code = "2014_demer"),
get_animal_projects(con, animal_project_code = "2014_DEMER")
)

# Select multiple values
multi_select <- c("2014_demer", "2015_dijle")
multi_select_df <- get_animal_projects(con, animal_project_code = multi_select)
expect_equal(
expect_identical(
multi_select_df %>% distinct(project_code) %>% pull() %>% sort(),
c(multi_select)
)
expect_equal(nrow(multi_select_df), 2)
expect_identical(nrow(multi_select_df), 2L)
})

test_that("get_animal_projects() returns projects of type 'animal'", {
expect_equal(
expect_identical(
get_animal_projects(con) %>% distinct(project_type) %>% pull(),
"animal"
)
40 changes: 20 additions & 20 deletions tests/testthat/test-get_tags.R
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ test_that("get_tags() returns the expected columns", {
"tag_id",
"tag_device_id"
)
expect_equal(names(df), expected_col_names)
expect_identical(names(df), expected_col_names)
})

test_that("get_tags() allows selecting on tag_serial_number", {
@@ -82,21 +82,21 @@ test_that("get_tags() allows selecting on tag_serial_number", {
# Select single value
single_select <- "1187450" # From 2014_demer
single_select_df <- get_tags(con, tag_serial_number = single_select)
expect_equal(
expect_identical(
single_select_df %>% distinct(tag_serial_number) %>% pull(),
c(single_select)
)
expect_equal(nrow(single_select_df), 1)
expect_identical(nrow(single_select_df), 1L)
# Note that not all tag_serial_number return a single row, see further test

# Select multiple values
multi_select <- c(1187449, "1187450") # Integers are allowed
multi_select_df <- get_tags(con, tag_serial_number = multi_select)
expect_equal(
expect_identical(
multi_select_df %>% distinct(tag_serial_number) %>% pull() %>% sort(),
c(as.character(multi_select)) # Output will be all character
)
expect_equal(nrow(multi_select_df), 2)
expect_identical(nrow(multi_select_df), 2L)
})

test_that("get_tags() allows selecting on tag_type", {
@@ -107,7 +107,7 @@ test_that("get_tags() allows selecting on tag_type", {
# Select single value
single_select <- "archival"
single_select_df <- get_tags(con, tag_type = single_select)
expect_equal(
expect_identical(
single_select_df %>% distinct(tag_type) %>% pull(),
c(single_select)
)
@@ -116,7 +116,7 @@ test_that("get_tags() allows selecting on tag_type", {
# Select multiple values
multi_select <- c("acoustic-archival", "archival")
multi_select_df <- get_tags(con, tag_type = multi_select)
expect_equal(
expect_identical(
multi_select_df %>% distinct(tag_type) %>% pull() %>% sort(),
c(multi_select)
)
@@ -131,7 +131,7 @@ test_that("get_tags() allows selecting on tag_subtype", {
# Select single value
single_select <- "built-in"
single_select_df <- get_tags(con, tag_subtype = single_select)
expect_equal(
expect_identical(
single_select_df %>% distinct(tag_subtype) %>% pull(),
c(single_select)
)
@@ -140,7 +140,7 @@ test_that("get_tags() allows selecting on tag_subtype", {
# Select multiple values
multi_select <- c("built-in", "range")
multi_select_df <- get_tags(con, tag_subtype = multi_select)
expect_equal(
expect_identical(
multi_select_df %>% distinct(tag_subtype) %>% pull() %>% sort(),
c(multi_select)
)
@@ -155,21 +155,21 @@ test_that("get_tags() allows selecting on acoustic_tag_id", {
# Select single value
single_select <- "A69-1601-16130" # From 2014_demer
single_select_df <- get_tags(con, acoustic_tag_id = single_select)
expect_equal(
expect_identical(
single_select_df %>% distinct(acoustic_tag_id) %>% pull(),
c(single_select)
)
expect_equal(nrow(single_select_df), 1)
expect_identical(nrow(single_select_df), 1L)
# Note that not all acoustic_tag_id return a single row, e.g. "A180-1702-48973"

# Select multiple values
multi_select <- c("A69-1601-16129", "A69-1601-16130")
multi_select_df <- get_tags(con, acoustic_tag_id = multi_select)
expect_equal(
expect_identical(
multi_select_df %>% distinct(acoustic_tag_id) %>% pull() %>% sort(),
c(multi_select)
)
expect_equal(nrow(multi_select_df), 2)
expect_identical(nrow(multi_select_df), 2L)
})

test_that("get_tags() allows selecting on multiple parameters", {
@@ -180,14 +180,14 @@ test_that("get_tags() allows selecting on multiple parameters", {
tag_subtype = "animal",
acoustic_tag_id = "A69-1601-16130"
)
expect_equal(nrow(multiple_parameters_df), 1)
expect_identical(nrow(multiple_parameters_df), 1L)
})

test_that("get_tags() can return multiple rows for a single tag", {
# A sentinel acoustic-archival tag with temperature + pressure sensor
tag_1_df <- get_tags(con, tag_serial_number = 1400185)
expect_equal(nrow(tag_1_df), 2) # 2 rows: temperature + presure
expect_equal(
expect_identical(nrow(tag_1_df), 2L) # 2 rows: temperature + presure
expect_identical(
tag_1_df %>%
dplyr::arrange(acoustic_tag_id) %>%
distinct(tag_type, tag_subtype, sensor_type, acoustic_tag_id),
@@ -202,8 +202,8 @@ test_that("get_tags() can return multiple rows for a single tag", {

# A built-in acoustic tag with two protocols: https://github.com/inbo/etn/issues/177#issuecomment-925578186
tag_2_df <- get_tags(con, tag_serial_number = 461076)
expect_equal(nrow(tag_2_df), 2) # 2 rows: A180 + H170
expect_equal(
expect_identical(nrow(tag_2_df), 2L) # 2 rows: A180 + H170
expect_identical(
tag_2_df %>%
dplyr::arrange(acoustic_tag_id) %>%
distinct(tag_type, tag_subtype, sensor_type, acoustic_tag_id),
@@ -219,11 +219,11 @@ test_that("get_tags() can return multiple rows for a single tag", {

test_that("get_tags() returns correct tag_type and tag_subtype", {
df <- get_tags(con)
expect_equal(
expect_identical(
df %>% distinct(tag_type) %>% pull() %>% sort(),
c("acoustic", "acoustic-archival", "archival")
)
expect_equal(
expect_identical(
df %>% distinct(tag_subtype) %>% pull() %>% sort(),
c("animal", "built-in", "range", "sentinel")
)