Skip to content

Commit

Permalink
Merge pull request #1 from AugustT/master
Browse files Browse the repository at this point in the history
Fixing test failures
  • Loading branch information
drnickisaac authored Nov 13, 2020
2 parents 335c985 + d5b0625 commit 704adc1
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 101 deletions.
44 changes: 19 additions & 25 deletions tests/testthat/testdataDiagnostics.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,25 @@ test_that("Test dataDiagnostics", {
"2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026",
"2027", "2028", "2029")), .Names = "RecordsPerYear"), class = "table")
visittop50 <- structure(list(time_period = structure(c(14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14713,
14713, 14713), class = "Date"),
#site = structure(c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
# 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
# 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 34L, 35L, 36L, 37L,
# 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 1L,
# 2L, 3L), .Label = c("A1", "A10", "A11", "A12", "A13", "A14",
# "A15", "A16", "A17", "A18", "A19", "A2", "A20", "A21", "A22",
# "A23", "A24", "A25", "A26", "A27", "A28", "A29", "A3", "A30",
# "A31", "A32", "A33", "A34", "A35", "A36", "A37", "A38", "A39",
# "A48", "A49", "A5", "A50", "A6", "A7", "A8", "A9"), class = "factor"),
# "A4", "A40", "A41", "A42", "A43", "A44", "A45", "A46", "A47",
site = structure(c("A1", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A2", "A20", "A21", "A22",
"A23", "A24", "A25", "A26", "A27", "A28", "A29", "A3", "A30", "A31", "A32", "A33", "A34", "A35",
"A36", "A37", "A38", "A4", "A40", "A41", "A42", "A44", "A45", "A46", "A47", "A48", "A49", "A5",
"A50", "A6", "A7", "A8", "A9", "A1", "A10", "A11"), class = "chr"),
listLength = c(1L, 5L, 5L, 1L, 3L, 3L, 1L, 1L, 1L, 2L, 2L,
5L, 6L, 4L, 1L, 5L, 1L, 5L, 4L, 5L, 3L, 7L, 2L, 4L, 5L, 2L,
2L, 5L, 1L, 6L, 5L, 1L, 2L, 2L, 4L, 3L, 3L, 3L, 2L, 1L, 5L,
2L, 1L, 5L, 2L, 2L, 3L, 5L, 5L, 1L)), .Names = c("time_period",
"site", "listLength"), row.names = c(NA, 50L), class = "data.frame")
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657,
14657, 14657, 14657, 14657, 14657, 14657, 14657, 14657, 14713,
14713, 14713), class = "Date"),
site = c("A1", "A11", "A12",
"A13", "A14", "A15", "A16", "A17", "A18", "A19", "A2", "A20",
"A21", "A22", "A23", "A24", "A25", "A26", "A27", "A28", "A29",
"A3", "A30", "A31", "A32", "A33", "A34", "A35", "A36", "A37",
"A38", "A4", "A40", "A41", "A42", "A44", "A45", "A46", "A47",
"A48", "A49", "A5", "A50", "A6", "A7", "A8", "A9", "A1", "A10",
"A11"),
listLength = c(1L, 5L, 5L, 1L, 3L, 3L, 1L, 1L, 1L, 2L,
2L, 5L, 6L, 4L, 1L, 5L, 1L, 5L, 4L, 5L, 3L, 7L, 2L, 4L, 5L, 2L,
2L, 5L, 1L, 6L, 5L, 1L, 2L, 2L, 4L, 3L, 3L, 3L, 2L, 1L, 5L, 2L,
1L, 5L, 2L, 2L, 3L, 5L, 5L, 1L)),
row.names = c(NA, 50L),
class = "data.frame")

coefModRecs <- structure(c(-26329.52105, 13.40902), .Names = c("(Intercept)",
"time_period"))
Expand Down
32 changes: 17 additions & 15 deletions tests/testthat/testdetection_phenology.r
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
context("Test plot_DetectionPhenology")

test_that("Test plot_DetectionPhenology", {

sink(file = ifelse(Sys.info()["sysname"] == "Windows",
"NUL",
"/dev/null"))
# Create data
n <- 15000 #size of dataset
nyr <- 20 # number of years in data
Expand All @@ -28,6 +23,13 @@ test_that("Test plot_DetectionPhenology", {
# the date of visit is selected at random from those created earlier
survey <- sample(rDates, size = n, TRUE)

test_that("Test plot_DetectionPhenology", {

sink(file = ifelse(Sys.info()["sysname"] == "Windows",
"NUL",
"/dev/null"))


# format data
suppressWarnings({visitData <- formatOccData(taxa = taxa,
site = site,
Expand All @@ -45,9 +47,8 @@ test_that("Test plot_DetectionPhenology", {

# quick check this output is as expected
expect_equal(head(modelresults$BUGSoutput$sims.list$alpha.p[,1]),
c(-2.686388, -2.483351, -2.359051, -2.337057, -2.599563, -2.637756),
# c(-3.0072164156934, -2.17484348943153, -2.04228261009605, -2.53916362332146,
# -3.18523796966506, -3.02335381838008),
c(-3.0072164156934, -2.17484348943153, -2.04228261009605, -2.53916362332146,
-3.18523796966506, -3.02335381838008),
tolerance = 1e-7)

# create some model results without Julian date
Expand All @@ -68,13 +69,14 @@ test_that("Test plot_DetectionPhenology", {

# create expected data
head_data_bin <- c(1L, 2L, 3L, 4L, 5L, 6L)
#head_data_mean_pDet <- c(0.07952482, 0.07952476, 0.07952399, 0.07951970, 0.07951016, 0.07955624)
#head_data_lower95CI <- c(0.03930188, 0.03930189, 0.03930365, 0.03936658, 0.04011354, 0.04298810)
#head_data_upper95CI <- c(0.1448798, 0.1448798, 0.1448798, 0.1448798, 0.1448798, 0.1448754)
head_data_mean_pDet <- c(0.06916837, 0.06916837, 0.06916812, 0.06916089, 0.06902980, 0.06106107)
head_data_lower95CI <- c(0.039254824, 0.039254824, 0.039254824, 0.039254824, 0.039254824, 0.008464417)
head_data_upper95CI <- c(0.1108772, 0.1108772, 0.1108772, 0.1108772, 0.1108772, 0.1108772)
head_data_JulianDay <- c(1.00000, 34.09091, 67.18182, 100.27273, 133.36364, 166.45455)
head_data_mean_pDet <- c(0.0795248229875861, 0.0795247569031214, 0.0795239877368355,
0.0795197030738163, 0.0795101592056275, 0.0795562377193303)
head_data_lower95CI <- c(0.0393018751339037, 0.0393018916184026, 0.0393036478896574,
0.0393665776000181, 0.040113536889726, 0.0429881045873861)
head_data_upper95CI <- c(0.144879763944464, 0.144879763944464, 0.144879763944464, 0.144879763944464,
0.144879763944464, 0.144875423401869)
head_data_JulianDay <- c(1, 34.0909090909091, 67.1818181818182, 100.272727272727, 133.363636363636,
166.454545454545)


expect_identical(names(results), c("data", "layers", "scales", "mapping", "theme", "coordinates", "facet", "plot_env", "labels"))
Expand Down
42 changes: 17 additions & 25 deletions tests/testthat/testformatOccData.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,15 @@ test_that("Test formatOccData", {
6L), class = "data.frame")


head_occDetdata <- structure(list(visit = c("A102010-04-141", "A102010-04-221", "A102010-08-291",
"A102010-11-041", "A102011-02-091", "A102011-03-091"),
site = structure(c(2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("A1", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A2", "A20", "A21",
"A22", "A23", "A24", "A25", "A26", "A27", "A28", "A29", "A3",
"A30", "A31", "A32", "A33", "A34", "A35", "A36", "A37", "A38",
"A39", "A4", "A40", "A41", "A42", "A43", "A44", "A45", "A46",
"A47", "A48", "A49", "A5", "A50", "A6", "A7", "A8", "A9"), class = "factor"),
L = c(5L, 5L, 2L, 2L, 1L, 2L),
year = c(2010, 2010, 2010, 2010, 2011, 2011)),
.Names = c("visit", "site", "L", "TP"),
row.names = c(1L, 6L, 11L, 13L, 15L, 16L), class = "data.frame")

head_occDetdata <- structure(list(visit = c("A102010-04-141", "A102010-04-221",
"A102010-08-291", "A102010-11-041",
"A102011-02-091", "A102011-03-091"),
site = c("A10", "A10", "A10", "A10", "A10",
"A10"),
L = c(5L, 5L, 2L, 2L, 1L, 2L),
TP = c(2010, 2010, 2010, 2010, 2011, 2011)),
row.names = c(1L, 6L, 11L, 13L, 15L, 16L),
class = "data.frame")

expect_identical(head(visitData$spp_vis), head_spp_vis)
expect_identical(head(visitData$occDetdata), head_occDetdata)
Expand Down Expand Up @@ -112,18 +108,14 @@ test_that("Test formatOccData specified closure period", {
expect_warning(visitData <- formatOccData(taxa = taxa, site = site, survey = survey, closure_period = closure_period),
'871 out of 15000 observations will be removed as duplicates')

head_occDetdata_cp <- structure(list(visit = c("A102010-04-141", "A102010-04-221", "A102010-08-291",
"A102010-11-041", "A102011-02-091", "A102011-03-091"),
site = structure(c(2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("A1", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A2", "A20", "A21",
"A22", "A23", "A24", "A25", "A26", "A27", "A28", "A29", "A3",
"A30", "A31", "A32", "A33", "A34", "A35", "A36", "A37", "A38",
"A39", "A4", "A40", "A41", "A42", "A43", "A44", "A45", "A46",
"A47", "A48", "A49", "A5", "A50", "A6", "A7", "A8", "A9"), class = "factor"),
L = c(5L, 5L, 2L, 2L, 1L, 2L),
year = c(1L, 1L, 1L, 1L, 1L, 1L)),
.Names = c("visit", "site", "L", "TP"),
row.names = c(1L, 6L, 11L, 13L, 15L, 16L), class = "data.frame")
head_occDetdata_cp <- structure(list(visit = c("A102010-04-141", "A102010-04-221",
"A102010-08-291", "A102010-11-041",
"A102011-02-091", "A102011-03-091"),
site = c("A10", "A10", "A10", "A10", "A10", "A10"),
L = c(5L, 5L, 2L, 2L, 1L, 2L),
TP = c(1L, 1L, 1L, 1L, 1L, 1L)),
row.names = c(1L, 6L, 11L, 13L, 15L, 16L),
class = "data.frame")

expect_identical(head(visitData$occDetdata), head_occDetdata_cp)

Expand Down
20 changes: 14 additions & 6 deletions tests/testthat/testfrescalo.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("Test frescalo")

### Frescalo testing is currently skipped if not on a ###
### windows machine, or is libcurl is not supported. ###
### windows machine, or if libcurl is not supported. ###

# Create data
n <- 1500 #size of dataset
Expand Down Expand Up @@ -38,14 +38,16 @@ weights$W <- runif(n = nrow(weights), min = 0, max = 1)

frespath <- file.path(tempdir(), 'fres.exe')

toms_PC <- Sys.info()['nodename'] == "WLD-D5P2J42"
toms_PC <- Sys.info()['nodename'] == "WLL-3RHYM53"

if(toms_PC) frespath <- 'C:/Frescalo_3a_windows.exe'

test_that("Test errors", {

skip_on_appveyor()
skip_on_travis()
if (!capabilities('libcurl')) skip('skipping as libcurl not supported')
if(grep("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo')

if(!toms_PC){
Expand Down Expand Up @@ -109,8 +111,10 @@ test_that("Test errors", {

test_that("Runs without error", {

skip_on_appveyor()
skip_on_travis()
if (!capabilities('libcurl')) skip('skipping as libcurl not supported')
if(grep("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo')

# This first run is done using years
Expand Down Expand Up @@ -226,8 +230,10 @@ weights$W <- runif(n = nrow(weights), min = 0, max = 1)

test_that("Test plotting", {

skip_on_travis()
skip_on_appveyor()
if (!capabilities('libcurl')) skip('skipping as libcurl not supported')
if(grep("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo')

# test plotting
Expand Down Expand Up @@ -293,8 +299,10 @@ weights$W <- runif(n = nrow(weights), min = 0, max = 1)

test_that("Runs high value of phi", {

skip_on_appveyor()
skip_on_travis()
if (!capabilities('libcurl')) skip('skipping as libcurl not supported')
if(grep("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if(grepl("mac", .Platform$pkgType)) skip('Frescalo exe does not run on Mac OS')
if (.Platform$OS.type == "windows" & !toms_PC) skip('Carbon black blocks Frescalo')

# test a very low value of phi
Expand Down
Loading

0 comments on commit 704adc1

Please sign in to comment.