diff --git a/tests/testthat/testdataDiagnostics.r b/tests/testthat/testdataDiagnostics.r index ba2b0bc..bb68c1c 100644 --- a/tests/testthat/testdataDiagnostics.r +++ b/tests/testthat/testdataDiagnostics.r @@ -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")) diff --git a/tests/testthat/testdetection_phenology.r b/tests/testthat/testdetection_phenology.r index 634bdb1..9f1aa02 100644 --- a/tests/testthat/testdetection_phenology.r +++ b/tests/testthat/testdetection_phenology.r @@ -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 @@ -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, @@ -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 @@ -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")) diff --git a/tests/testthat/testformatOccData.r b/tests/testthat/testformatOccData.r index 73ac99c..12086a3 100755 --- a/tests/testthat/testformatOccData.r +++ b/tests/testthat/testformatOccData.r @@ -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) @@ -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) diff --git a/tests/testthat/testfrescalo.r b/tests/testthat/testfrescalo.r index 02ebf66..87c43b1 100755 --- a/tests/testthat/testfrescalo.r +++ b/tests/testthat/testfrescalo.r @@ -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 @@ -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){ @@ -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 @@ -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 @@ -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 diff --git a/tests/testthat/testtelfer.r b/tests/testthat/testtelfer.r index f51bc11..0147b83 100644 --- a/tests/testthat/testtelfer.r +++ b/tests/testthat/testtelfer.r @@ -10,36 +10,50 @@ time_period <- sample(1:3, SS, replace = TRUE) df <- unique(data.frame(taxa, site, time_period)) # This is what the results should look like -results <- structure(list(taxa = structure(1:26, .Label = c("a", "b", "c", - "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", - "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"), class = "factor"), - Nsite_1.x = c(7, 5, 11, 6, 8, 12, 13, 10, 11, 7, 9, 10, 10, - 8, 6, 10, 10, 9, 7, 9, 7, 12, 7, 6, 11, 6), - Nsite_2.x = c(8, 8, 10, 11, 14, 12, 8, 8, 8, 10, 10, 10, - 9, 11, 7, 13, 9, 10, 12, 9, 14, 11, 5, 11, 13, 8), - Telfer_1_2 = c(-0.73732519, -0.77133792, -0.09783170, 0.70566506, 1.84449356, - 0.79320432, -1.39542120, -0.88966350, -0.98871825, 0.14526451, 0.02084756, -0.03627006, - -0.45903684, 0.49957587, -1.23170170, 1.26438351, -0.45903684, 0.02084756, 1.02785421, - -0.39539529, 1.98143673, 0.30605205, -2.22583487, 0.70566506, 1.25996498, - -0.72891844), Nsite_1.y = c(7, 5, 11, 6, 8, 12, 13, 10, 11, 7, 9, 10, 10, 8, - 6, 10, 10, 9, 7, 9, 7, 12, 7, 6, 11, 6), - Nsite_3.x = c(10, 8, 11, 11, 7, 11, 12, 9, 7, 11, 10, 9, 9, 7, 11, 5, 10, 12, 9, 8, 7, 10, 10, 11, 12, 8), - Telfer_1_3 = c(0.4282569, -0.9490873, 0.6579022, 1.2282920, -1.2888609, 0.6135323, - 1.0747447, -0.2624847, -1.2994921, 1.0052868, 0.2779805, -0.2624847, - -0.2624847, -1.2888609, 1.2282920, -2.4181066, - 0.2248821, 1.2932700, -0.1487729, -0.7373091, -1.3469912, 0.1331646, - 0.4282569, 1.2282920, 1.1469913, -0.7816810), - Nsite_2.y = c(8, 8, 10, 11, 14, 12, 8, 8, 8, 10, 10, 10, 9, 11, 7, 13, 9, 10, 12, 9, 14, 11, 5, 11, 13, 8), - Nsite_3.y = c(10, 8, 11, 11, 7, 11, 12, 9, 7, 11, 10, 9, 9, 7, 11, 5, 10, 12, 9, 8, 7, 10, 10, 11, 12, 8), - Telfer_2_3 = c(0.241879867, -1.128220065, 0.905222087, 0.882140381, -0.835189914, 0.855157996, - 1.611979800, -0.436860690, -1.846284033, 0.905222087, 0.325816517, - -0.253589053, -0.340138161, -1.278488893, 0.896127341, -2.002866510, - 0.290092553, 1.495399688, -0.112055477, -0.982085822, -0.835189914, 0.352123266, - 0.006522637, 0.882140381, 1.275183707, -1.128220065)), - .Names = c("taxa", - "Nsite_1.x", "Nsite_2.x", "Telfer_1_2", "Nsite_1.y", "Nsite_3.x", - "Telfer_1_3", "Nsite_2.y", "Nsite_3.y", "Telfer_2_3"), row.names = c(NA, - -26L), class = "data.frame") +results <- structure(list(taxa = c("a", "b", "c", "d", "e", "f", "g", "h", + "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", + "v", "w", "x", "y", "z"), + Nsite_1.x = c(7, 5, 11, 6, 8, 12, 13, + 10, 11, 7, 9, 10, 10, 8, 6, 10, 10, 9, + 7, 9, 7, 12, 7, 6, 11, 6), + Nsite_2.x = c(8, 8, 10, 11, 14, 12, 8, 8, 8, 10, 10, 10, + 9, 11, 7, 13, 9, 10, 12, 9, 14, 11, 5, 11, 13, 8), + Telfer_1_2 = c(-0.737325194162432, -0.771337920914978, + -0.0978316993182738, 0.705665061130678, + 1.84449355838129, 0.793204324994675, + -1.39542120066517, -0.889663497755277, + -0.988718249517388, 0.145264509176636, + 0.0208475603716532, -0.0362700616533217, + -0.459036841151605, 0.49957587189965, -1.23170170347477, + 1.26438350620118, -0.459036841151605, 0.0208475603716532, + 1.0278542125157, -0.395395287450087, 1.98143673331934, + 0.306052052307134, -2.22583487465281, 0.705665061130678, + 1.25996497575673, -0.728918435468554), + Nsite_1.y = c(7, 5, 11, 6, 8, 12, 13, 10, 11, 7, 9, 10, 10, + 8, 6, 10, 10, 9, 7, 9, 7, 12, 7, 6, 11, 6), + Nsite_3.x = c(10, 8, 11, 11, 7, 11, 12, 9, 7, 11, 10, 9, + 9, 7, 11, 5, 10, 12, 9, 8, 7, 10, 10, 11, 12, 8), + Telfer_1_3 = c(0.428256932967209, -0.949087297190003, 0.65790219617248, 1.22829202628365, + -1.28886094429482, 0.613532330883972, 1.07474465397477, -0.262484704574745, + -1.29949214495499, 1.00528677409354, 0.277980477724887, -0.262484704574745, + -0.262484704574745, -1.28886094429482, 1.22829202628365, + -2.41810658165437, 0.224882116972965, 1.29327001776924, -0.148772908159123, + -0.737309062319468, -1.3469911660205, 0.133164595928159, + 0.42825693296721, 1.22829202628365, 1.14699133920679, -0.781680952309443), + Nsite_2.y = c(8, 8, 10, 11, 14, 12, 8, 8, 8, 10, 10, 10, + 9, 11, 7, 13, 9, 10, 12, 9, 14, 11, 5, 11, 13, 8), + Nsite_3.y = c(10, 8, 11, 11, 7, 11, 12, 9, 7, 11, 10, 9, 9, 7, 11, + 5, 10, 12, 9, 8, 7, 10, 10, 11, 12, 8), + Telfer_2_3 = c(0.241879867181403, -1.1282200653054, 0.905222087260817, 0.882140380723752, + -0.835189914093116, 0.855157996286309, 1.61197979966821, -0.436860689687682, + -1.84628403251525, 0.905222087260817, 0.325816517346919, + -0.253589052566972, -0.340138161126636, -1.27848889281263, + 0.896127341439063, -2.00286651006585, 0.290092552577541, + 1.49539968751045, -0.112055476633155, -0.982085821852136, + -0.835189914093116, 0.352123266172587, 0.00652263716418258, + 0.882140380723752, 1.27518370742708, -1.12822006530541)), + row.names = c(NA, -26L), + class = "data.frame") ###################### test_that("Test errors and warnings", {