Skip to content

Commit b476372

Browse files
committed
Moved package loading in tests from individual test files
1 parent 2d63744 commit b476372

16 files changed

+426
-457
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Replaced many `expect_equivalent()` with `expect_equal(,ignore_attr=TRUE)` as `expect_equivalent()` was deprecated.
77
* Had to correct many tests where I expected just `matrix` but the class was `c("matrix","array")`.
88
* Had to handle multiple warnings for some tests (see [this article](https://testthat.r-lib.org/articles/third-edition.html#warnings)).
9-
* Removed many `require()` that were not needed.
9+
* Moved all `require()` in individual files to `testthat.R`. This removed many `require()` that were not needed.
1010

1111
* `GompertzFuns()`: Accepted pull request related to [#112](https://github.com/fishR-Core-Team/FSA/issues/112) that fixed several typos and dead links in the documentation ... thanks Arni. Corrected the erroneous reference to t* (should have been t0) in the documentation for the Gompertz function (fixes [#113](https://github.com/fishR-Core-Team/FSA/issues/113) ... thanks again to Arni).
1212

man/FSA.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/growthModels.Rd

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
77
# * https://testthat.r-lib.org/articles/special-files.html
88

9-
library(testthat)
10-
library(FSA)
9+
suppressPackageStartupMessages(library(testthat))
10+
suppressPackageStartupMessages(library(FSA))
1111

12+
# packages used in tests (load here instead of in individual files)
13+
suppressPackageStartupMessages(library(FSAdata))
14+
suppressPackageStartupMessages(library(fishmethods))
15+
suppressPackageStartupMessages(library(DescTools))
16+
suppressPackageStartupMessages(library(dunn.test))
17+
suppressPackageStartupMessages(library(lmtest))
18+
suppressPackageStartupMessages(library(nlme))
19+
suppressPackageStartupMessages(library(psych))
20+
suppressPackageStartupMessages(library(tibble))
21+
22+
# Test the package
1223
test_check("FSA")

tests/testthat/testthat_AgeComparisons.R

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,31 @@ test_that("ageBias() symmetry tests match results in Evans and Hoenig (2008)",{
148148
})
149149

150150
test_that("test ageBias() against compare2() with AlewifeLH data",{
151-
if (require(FSAdata,quietly=TRUE) & require(fishmethods,quietly=TRUE)) {
152-
data(AlewifeLH,package="FSAdata")
153-
ab2 <- compare2(AlewifeLH,barplot=FALSE)
154-
## no continuity correction
155-
suppressWarnings(ab1 <- ageBias(scales~otoliths,data=AlewifeLH,
156-
ref.lab="Otolith Age",nref.lab="Scale Age"))
157-
junk <- capture.output( ab1sum <- summary(ab1) )
158-
expect_equal(ab1sum[ab1sum$symTest=="McNemar","chi.sq"], ab2$McNemar$Chisq)
159-
expect_equal(ab1sum[ab1sum$symTest=="McNemar","p"], ab2$McNemar$pvalue)
160-
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","chi.sq"],
161-
ab2$Evans_Hoenig$Chisq)
162-
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","p"],
163-
ab2$Evans_Hoenig$pvalue)
164-
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","df"],
165-
ab2$Evans_Hoenig$df)
166-
## Yates continuity correction
167-
junk <- capture.output( ab1sum2 <- summary(ab1,what="McNemar",
168-
cont.corr="Yates") )
169-
expect_equal(ab1sum2[1,"chi.sq"], ab2$McNemar_continuity_correction$Chisq)
170-
expect_equal(ab1sum2[1,"p"], ab2$McNemar_continuity_correction$pvalue)
171-
## Edwards continuity correction
172-
ab3 <- compare2(AlewifeLH,correct="Edwards",barplot=FALSE)
173-
junk <- capture.output( ab1sum3 <- summary(ab1,what="McNemar",
174-
cont.corr="Edwards") )
175-
expect_equal(ab1sum3[1,"chi.sq"], ab3$McNemar_continuity_correction$Chisq)
176-
expect_equal(ab1sum3[1,"p"], ab3$McNemar_continuity_correction$pvalue)
177-
}
151+
data(AlewifeLH,package="FSAdata")
152+
ab2 <- fishmethods::compare2(AlewifeLH,barplot=FALSE)
153+
## no continuity correction
154+
suppressWarnings(ab1 <- ageBias(scales~otoliths,data=AlewifeLH,
155+
ref.lab="Otolith Age",nref.lab="Scale Age"))
156+
junk <- capture.output( ab1sum <- summary(ab1) )
157+
expect_equal(ab1sum[ab1sum$symTest=="McNemar","chi.sq"], ab2$McNemar$Chisq)
158+
expect_equal(ab1sum[ab1sum$symTest=="McNemar","p"], ab2$McNemar$pvalue)
159+
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","chi.sq"],
160+
ab2$Evans_Hoenig$Chisq)
161+
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","p"],
162+
ab2$Evans_Hoenig$pvalue)
163+
expect_equal(ab1sum[ab1sum$symTest=="EvansHoenig","df"],
164+
ab2$Evans_Hoenig$df)
165+
## Yates continuity correction
166+
junk <- capture.output( ab1sum2 <- summary(ab1,what="McNemar",
167+
cont.corr="Yates") )
168+
expect_equal(ab1sum2[1,"chi.sq"], ab2$McNemar_continuity_correction$Chisq)
169+
expect_equal(ab1sum2[1,"p"], ab2$McNemar_continuity_correction$pvalue)
170+
## Edwards continuity correction
171+
ab3 <- fishmethods::compare2(AlewifeLH,correct="Edwards",barplot=FALSE)
172+
junk <- capture.output( ab1sum3 <- summary(ab1,what="McNemar",
173+
cont.corr="Edwards") )
174+
expect_equal(ab1sum3[1,"chi.sq"], ab3$McNemar_continuity_correction$Chisq)
175+
expect_equal(ab1sum3[1,"p"], ab3$McNemar_continuity_correction$pvalue)
178176
})
179177

180178
test_that("ageBias() compared to http://www.nefsc.noaa.gov/fbp/age-prec/ calculations for AlewifeLH data",{
@@ -285,4 +283,3 @@ test_that("agePrecision() differences for simple data with NA values",{
285283
ap135 <- agePrecision(~age1+age3+age5,data=tmp)
286284
expect_equal(round(ap135$PercAgree,4),50.0000)
287285
})
288-

0 commit comments

Comments
 (0)