Skip to content

Commit

Permalink
reduce tests runtime using smaller test data
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Jan 26, 2024
1 parent bc7b7cb commit f6484ad
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/helper-model.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(wqtrends)

# data to model
tomod <- subset(rawdat, rawdat$station == 34 & rawdat$param == 'chl')
tomod <- subset(rawdat, rawdat$station == 34 & rawdat$param == 'chl' & yr > 2015)

# test model
mod <- anlz_gam(tomod, trans = 'log10')
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-anlz_avgseason.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ test_that("Checking anlz_avgseason", {

result <- anlz_avgseason(mod, doystr = 90, doyend = 180)

expect_equal(nrow(result), 29)
expect_equal(nrow(result), 4)

})

test_that("Checking anlz_avgseason, no transformation", {

result <- anlz_avgseason(modident, doystr = 90, doyend = 180)

expect_equal(nrow(result), 29)
expect_equal(nrow(result), 4)

})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-anlz_backtrans.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("Checking anlz_backtrans, log10", {
.[1:4] %>%
round(1)

expect_equal(result, c(2.8, 3.1, 2.5, 4.2))
expect_equal(result, c(4.4, 9.3, 7.8, 6.1))

})

Expand Down
11 changes: 7 additions & 4 deletions tests/testthat/test-anlz_gam.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
test_that("Checking multiple parameters in anlz_gam", {

rawdat <- rawdat %>% dplyr::filter(station %in% 32)
expect_error(anlz_gam(rawdat), 'More than one parameter found in input data')
rawdatchk <- rawdat %>% dplyr::filter(station %in% 32)
expect_error(anlz_gam(rawdatchk), 'More than one parameter found in input data')

})

test_that("Checking multiple stations anlz_gam", {

rawdat <- rawdat %>% dplyr::filter(param %in% 'chl')
expect_error(anlz_gam(rawdat), 'More than one station found in input data')
rawdatchk <- rawdat %>%
dplyr::filter(param %in% 'chl') %>%
dplyr::filter(yr > 2015) %>%
dplyr::filter(station %in% c(32, 34))
expect_error(anlz_gam(rawdatchk), 'More than one station found in input data')

})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-anlz_metseason.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ test_that("Checking anlz_metseason", {

result <- anlz_metseason(mod, doystr = 90, doyend = 180, nsim = 5)

expect_equal(nrow(result), 29)
expect_equal(nrow(result), 4)

})

test_that("Checking anlz_metseason, no transformation", {

result <- anlz_metseason(modident, doystr = 90, doyend = 180, nsim = 5)

expect_equal(nrow(result), 29)
expect_equal(nrow(result), 4)

})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-anlz_mixmeta.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("Checking anlz_mixmeta", {

avgseason <- anlz_metseason(mod, doystr = 90, doyend = 180)
result <- anlz_mixmeta(avgseason, yrstr = 2000, yrend = 2017)
result <- anlz_mixmeta(avgseason, yrstr = 2016, yrend = 2019)

expect_is(result, 'mixmeta')

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-anlz_perchg.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("Checking anlz_perchg", {

result <- anlz_perchg(mod, baseyr = 1990, testyr = 2016)
result <- anlz_perchg(mod, baseyr = 2016, testyr = 2019)

expect_equal(nrow(result), 1)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-anlz_prd.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("Checking anlz_prd", {
.[1:4] %>%
round(1)

expect_equal(result, c(`1` = 2.8, `2` = 2.5, `3` = 2.3, `4` = 2.1))
expect_equal(result, c(`1` = 6.6, `2` = 6.6, `3` = 6.6, `4` = 6.7))

})

Expand All @@ -16,7 +16,7 @@ test_that("Checking anlz_prd, annual = T", {
.[1:4] %>%
round(1)

expect_equal(result, c(`1` = 2.8, `2` = 2.5, `3` = 2.3, `4` = 2.1))
expect_equal(result, c(`1` = 6.6, `2` = 6.6, `3` = 6.6, `4` = 6.7))

})

2 changes: 1 addition & 1 deletion tests/testthat/test-anlz_prdday.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("Checking anlz_prdday", {
.[1:4] %>%
round(1)

expect_equal(result, c(4, 4, 3.9, 3.9))
expect_equal(result, c(6.3, 6.3, 6.3, 6.3))

})

2 changes: 1 addition & 1 deletion tests/testthat/test-anlz_smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test_that("Checking anlz_smooth", {
dplyr::pull(p.value) %>%
round(2)

expect_equal(result, 0)
expect_equal(result, 0.01)

})
16 changes: 8 additions & 8 deletions tests/testthat/test-anlz_trndseason.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
test_that("Checking anlz_trndseason, left window", {

result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 5) %>%
result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 2) %>%
dplyr::pull(pval) %>%
.[(length(.) - 3):length(.)]

expect_equal(sum(is.na(result)), 4)
expect_equal(sum(is.na(result)), 1)

})

test_that("Checking anlz_trndseason, center window", {

result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 5) %>%
result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 3) %>%
dplyr::pull(pval) %>%
.[(length(.) - 3):length(.)]

Expand All @@ -20,27 +20,27 @@ test_that("Checking anlz_trndseason, center window", {

test_that("Checking anlz_trndseason, right window", {

result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'right', win = 5) %>%
result <- anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'right', win = 2) %>%
dplyr::pull(pval) %>%
.[(length(.) - 3):length(.)]

expect_equal(sum(is.na(result)), 0)
expect_equal(sum(is.na(result)), 1)

})

test_that("Checking anlz_trndseason, max as metfun", {

result <- anlz_trndseason(mod, metfun = max, doystr = 90, doyend = 180, justify = 'right', win = 5, nsim = 5) %>%
result <- anlz_trndseason(mod, metfun = max, doystr = 90, doyend = 180, justify = 'right', win = 2, nsim = 5) %>%
dplyr::pull(pval) %>%
.[(length(.) - 3):length(.)]

expect_equal(sum(is.na(result)), 0)
expect_equal(sum(is.na(result)), 1)

})

test_that("Checking anlz_trndseason, error if metfun not mean and useave TRUE", {

expect_error(anlz_trndseason(mod, metfun = max, doystr = 90, doyend = 180, justify = 'right', win = 5, nsim = 5, useave = T))
expect_error(anlz_trndseason(mod, metfun = max, doystr = 90, doyend = 180, justify = 'right', win = 2, nsim = 5, useave = T))

})

10 changes: 5 additions & 5 deletions tests/testthat/test-show_metseason.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
test_that("Checking show_metseason class", {

result <- show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2000, yrend = 2017, ylab = 'Chlorophyll-a (ug/L)')
result <- show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)')

expect_is(result, 'ggplot')

})

test_that("Checking show_metseason class, identity", {

result <- show_metseason(modident, doystr = 90, doyend = 180, yrstr = 2000, yrend = 2017, ylab = 'Chlorophyll-a (ug/L)')
result <- show_metseason(modident, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)')

expect_is(result, 'ggplot')

})

test_that("Checking show_metseason class, max as metfun", {

result <- show_metseason(modident, metfun = max, doystr = 90, doyend = 180, yrstr = 2000, yrend = 2017, ylab = 'Chlorophyll-a (ug/L)', nsim = 5)
result <- show_metseason(modident, metfun = max, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)', nsim = 5)

expect_is(result, 'ggplot')

Expand All @@ -32,15 +32,15 @@ test_that("Checking show_metseason class, yrstr or yrend as NULL", {

test_that("Checking show_metseason class, yromit included", {

result <- show_metseason(modident, metfun = max, doystr = 90, doyend = 180, yrstr = 2000, yrend = 2017, ylab = 'Chlorophyll-a (ug/L)', nsim = 5, yromit = 2015)
result <- show_metseason(modident, metfun = max, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)', nsim = 5, yromit = 2015)

expect_is(result, 'ggplot')

})

test_that("Checking show_metseason class with useave = T", {

result <- show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2000, yrend = 2017, ylab = 'Chlorophyll-a (ug/L)', useave = T)
result <- show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)', useave = T)

expect_is(result, 'ggplot')

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-show_mettrndseason.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
test_that("Checking show_mettrndseason class", {

result <- show_mettrndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 5, ylab = 'Chlorophyll-a (ug/L)')
result <- show_mettrndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 5, ylab = 'Chlorophyll-a (ug/L)', nsim = 10)

expect_is(result, 'ggplot')

})

test_that("Checking show_mettrndseason class with cmbn as T", {

result <- show_mettrndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 5, ylab = 'Chlorophyll-a (ug/L)', cmbn = T)
result <- show_mettrndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 5, ylab = 'Chlorophyll-a (ug/L)', cmbn = T, nsim = 10)

expect_is(result, 'ggplot')

})

test_that("show_mettrndseason throws an error if cols length is not 4 for cmbn as F", {

expect_error(show_mettrndseason(mod, cols = c('red', 'blue')), "Four names or colors must be provided")
expect_error(show_mettrndseason(mod, cols = c('red', 'blue'), nsim = 10), "Four names or colors must be provided")

})

test_that("show_mettrndseason throws an error if cols length is not 3 for cmbn as T", {

expect_error(show_mettrndseason(mod, cols = c('red', 'blue'), cmbn = T), "Three names or colors must be provided")
expect_error(show_mettrndseason(mod, cols = c('red', 'blue'), cmbn = T, nsim = 10), "Three names or colors must be provided")

})
2 changes: 1 addition & 1 deletion tests/testthat/test-show_perchg.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("Checking show_perchg class", {

result <- show_perchg(mod, baseyr = 1990, testyr = 2017, ylab = 'Chlorophyll-a (ug/L)')
result <- show_perchg(mod, baseyr = 2016, testyr = 2019, ylab = 'Chlorophyll-a (ug/L)')

expect_is(result, 'ggplot')

Expand Down

0 comments on commit f6484ad

Please sign in to comment.