Skip to content

Commit

Permalink
Updating tests of showDigitizedImage
Browse files Browse the repository at this point in the history
  • Loading branch information
droglenc committed Feb 1, 2019
1 parent f91e449 commit f90280c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RFishBC
Version: 0.2.0.9000
Date: 2019-1-21
Date: 2019-2-2
Title: Back-Calculation of Fish Length
Authors@R: person("Derek","Ogle",
email="derek@derekogle.com",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# RFishBC 0.2.0.9000 ongoing
* Updated vignettes.
* Added more tests.
* `combineData()`: Modified. Fixed two bugs related to how age-0 fish with no measured annuli are combined (thanks to Rory Feeney). Fixed how returned results are sorted (by id, reading, and ann; rather than just id and ann).
* `digitizeRadii()`: Modified. Added `sbUnits=` for addressing [#36](https://github.com/droglenc/RFishBC/issues/36). Fixed poor warning message when `snap2transect=TRUE` and `makeTransect=FALSE`.
* `RFBCoptions()`: Modified. Added `showScaleBarLength=`, `scaleBarUnits=`, and `cex.scaleBar=`.
Expand Down
32 changes: 16 additions & 16 deletions R/showDigitizedImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ showDigitizedImage <- function(nms,deviceType,
if (num2do==1) {
### Make sure file is an RData file from digitizeRadii()
if (!isRData(nms))
STOP("File is not an RData file saved from 'digitizeRadii().")
STOP(nms," is not an RData file saved from 'digitizeRadii().")
dat <- readRDS(nms)
if (!inherits(dat,"RFishBC"))
STOP("File does not appear to be from 'digitizeRadii().")
STOP(nms," does not appear to be from 'digitizeRadii().")
iShowOneDigitizedImage(dat,deviceType,
showScaleBarLength,col.scaleBar,lwd.scaleBar,cex.scaleBar,
connect,col.connect,lwd.connect,
Expand All @@ -108,10 +108,10 @@ showDigitizedImage <- function(nms,deviceType,
for (i in seq_along(nms)) {
### Make sure each file is an RData file from digitizeRadii()
if (!isRData(nms[i]))
STOP(nms[i],"is not an RData file saved from 'digitizeRadii().")
STOP(nms[i]," is not an RData file saved from 'digitizeRadii().")
dat <- readRDS(nms[i])
if (!inherits(dat,"RFishBC"))
STOP(nms[i],"does not appear to be from 'digitizeRadii().")
STOP(nms[i]," does not appear to be from 'digitizeRadii().")
if (!is.null(tmp)) {
if (dat$image!=tmp) {
grDevices::dev.off()
Expand All @@ -135,7 +135,7 @@ showDigitizedImage <- function(nms,deviceType,
useArrows,pch.show[i],col.show[i],cex.show[i],
showAnnuliLabels=FALSE,annuliLabels="",
col.ann[i],cex.ann[i],offset.ann[i])
else {
else { # nocov start
## Show connected points if asked to do so
if (connect) graphics::lines(y~x,data=dat$pts,
lwd=lwd.connect[i],col=col.connect[i],
Expand All @@ -158,7 +158,7 @@ showDigitizedImage <- function(nms,deviceType,
graphics::points(dat$pts[nrow(dat$pts),],
pch=pch.show[i],col=col.show[i],cex=cex.show[i])
}
}
} # nocov end
}
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ iShowAnnuliLabels <- function(dat,annuliLabels,
## Find a position for the "arrow" or the annulus label based on the
## slope of the transect or the first and last selected points.
########################################################################
iFindLabelPos <- function(dat) { # nocov start
iFindLabelPos <- function(dat) {
## Get slope of transect if used, otherwise find rough value from 1st/ last pts
if (!is.null(dat$slpTransect)) slp <- dat$slpTransect
else {
Expand All @@ -261,17 +261,17 @@ iFindLabelPos <- function(dat) { # nocov start
if (dat$pts$x[nrow(dat$pts)]<dat$pts$x[1]) deg <- deg+180
## Convert absolute transect degrees into a position for the text/arrow
deg <- abs(deg)
if (deg>=0 & deg<=45) pos <- 1 # below
else if (deg>45 & deg<=90) pos <- 4 # right
else if (deg>90 & deg<=135) pos <- 2 # left
else if (deg>135 & deg<=180) pos <- 1 # below
else if (deg>180 & deg<=225) pos <- 1 # below
else if (deg>225 & deg<=270) pos <- 4 # right
else if (deg>270 & deg<=315) pos <- 2 # left
else if (deg>315 & deg<=360) pos <- 1 # below
if (deg>=0 & deg<=45) pos <- 1L # below
else if (deg>45 & deg<=90) pos <- 4L # right
else if (deg>90 & deg<=135) pos <- 2L # left
else if (deg>135 & deg<=180) pos <- 1L # below
else if (deg>180 & deg<=225) pos <- 1L # below
else if (deg>225 & deg<=270) pos <- 4L # right
else if (deg>270 & deg<=315) pos <- 2L # left
else if (deg>315 & deg<=360) pos <- 1L # below
## Return the position
pos
} # nocov end
}



Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test_MESSAGES.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ test_that("combineData() messages",{
test_that("showDigitizedImage() messages",{
expect_error(showDigitizedImage("small_ex.jpg"),
"not an RData file")
expect_error(showDigitizedImage(c("small_ex.jpg","Scale_1_DHO.rds")),
"not an RData file")
expect_error(showDigitizedImage("notRFishBC.rds"),
"does not appear to be from")
expect_error(showDigitizedImage(c("notRFishBC.rds","Scale_1_DHO.rds")),
"does not appear to be from")
expect_error(showDigitizedImage(c("Scale_1_DHO.rds","Scale_2_DHO.rds")),
"from different structure images")
expect_error(showDigitizedImage(c("Scale_1_DHO.rds","Oto140306_DHO.rds")),
Expand All @@ -182,12 +186,20 @@ test_that("showDigitizedImage() messages",{
"Can use only one")
expect_error(showDigitizedImage("Oto140306_DHO.rds",lwd.scaleBar=1:2),
"Can use only one")
expect_error(showDigitizedImage("Oto140306_DHO.rds",pch.show=c(1,"arrows")),
"'arrows' cannot be used")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",pch.show=1:3),
"was recycled")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",col.show=1:3),
"was recycled")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",cex.show=1:3),
"was recycled")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",
pch.show="arrows",col.show=1:3),
"was recycled")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",
pch.show="arrows",cex.show=1:3),
"was recycled")
expect_warning(showDigitizedImage("Oto140306_DHO.rds",
annuliLabels=1:5,col.ann=1:3),
"was recycled")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_OUTPUTS.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,12 @@ test_that("Miscellaneous internals output",{
expect_true(all(tmp2$agecap==4))
expect_true(all(tmp2$radcap==4*sqrt(2)/2))
expect_equal(tmp2$rad,(1:4)*sqrt(2)/2)

## Label positions
tmp <- RFishBC:::iFindLabelPos(dat1)
expect_is(tmp,"integer")
expect_equal(tmp,4)
tmp <- RFishBC:::iFindLabelPos(dat2)
expect_is(tmp,"integer")
expect_equal(tmp,1)
})

0 comments on commit f90280c

Please sign in to comment.