-
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.
Support measurement col checks in
check_dataset()
#3
* Add first draft of tests for `check_dataset()` #5 * Add ideas to fix weird 'reached time limit' error #9
- Loading branch information
Showing
6 changed files
with
156 additions
and
11 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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,82 @@ | ||
|
||
test_that("check_dataset prints table and results", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", "Eolophus roseicapilla") | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset errors in table and results", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", 2) | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset handles multiple rows with errors", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", "Eolophus roseicapilla"), | ||
occurrenceStatus = c("present", "present"), | ||
decimalLatitude = c(-35.310, "-35.273") | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset only checks columns that match DwC terms", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", "Eolophus roseicapilla"), | ||
occurrenceStatus = c("present", "present"), | ||
decimalLatitude = c(-35.310, "-35.273"), | ||
longitude = c(149.125, 149.133) | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset prints a maximum of 5 error messages", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", 2), | ||
occurrenceStatus = c("present", "blop"), | ||
decimalLatitude = c(-35.310, "-35.273"), | ||
decimalLongitude = c(149.125, "149.133"), | ||
coordinatePrecision = c(.0001, ".0001"), | ||
genus = 1:2 | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset notifies when data meets minimum Darwin Core column requirements", { | ||
df <- tibble::tibble( | ||
scientificName = c("Callocephalon fimbriatum", "Eolophus roseicapilla"), | ||
decimalLatitude = c(-35.310, -35.273), # deliberate error for demonstration purposes | ||
decimalLongitude = c(149.125, 149.133), | ||
eventDate = lubridate::dmy("14-01-2023", "15-01-2023"), | ||
occurrenceStatus = c("present", "present"), | ||
occurrenceID = c("d32ed0c8-d791-11ef-8000-01ff50b5e852", "d32ed0e6-d791-11ef-8000-01ff50b5e852"), | ||
basisOfRecord = "humanObservation", | ||
coordinateUncertaintyInMeters = 10, | ||
geodeticDatum = "WGS84" | ||
) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) | ||
|
||
test_that("check_dataset handles `set_measurements()`", { | ||
df <- tibble::tibble( | ||
Species = c("Toechima", "Callicoma serratifolia"), | ||
Latitude = c(-17.1, -30.3), | ||
Longitude = c(146.002, 153.003), | ||
measurementValue = c(81.4, NA), | ||
measurementID = c("LMA_g.m2|1", "LMA_g.m2|2"), | ||
measurementUnit = "g/m2", | ||
measurementType = "LMA" | ||
) |> | ||
tidyr::nest(measurementOrFact = c(measurementValue, measurementID, | ||
measurementUnit, measurementType)) | ||
|
||
expect_snapshot(cat(check_dataset(df))) | ||
}) |