Skip to content

Commit

Permalink
Mo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomased committed Dec 6, 2018
1 parent e4d304f commit f25b7cb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .covrignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ R/explorespec.R
R/hexplot.R
R/jndplot.R
R/legendtetra.R
R/parse_procspec.R
R/plot.rspec.R
R/plot.rimg.R
R/plot.colspace.R
R/procimg.R
R/aggplot.R
R/points.colspace.R
R/aggplot.R
Expand Down
2 changes: 1 addition & 1 deletion R/peakshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ peakshape <- function(rspecdata, select = NULL, lim = NULL,

if (any(Bmin > Bmin_all)) {
warning("Consider fixing ", dQuote("lim"), " in spectra with ",
Quote("incl.min"), " marked ", dQuote("No"),
dQuote("incl.min"), " marked ", dQuote("No"),
" to incorporate all minima in spectral curves",
call. = FALSE)
}
Expand Down
6 changes: 5 additions & 1 deletion man/peakshape.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions tests/testthat/test-coldist.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test_that("Errors", {

expect_error(coldist(vismodel(flowers, relative = FALSE), n = c(1, 2, 3, 4, 5), achro = FALSE), "different length")
expect_error(coldist(vismodel(flowers, relative = FALSE), n = c(1, 2, 3), achro = FALSE), "different length")
expect_error(coldist(vismodel(flowers, relative = FALSE), subset = c('Goodenia', 'Xyris', "Eucalyptus"), achro = FALSE), "Too many")
})

test_that("Equivalent", {
Expand Down Expand Up @@ -51,13 +52,33 @@ test_that("Options", {

test_that("jnd transform", {
data(flowers)
library(digest)

vis.flowers <- vismodel(flowers, visual = 'apis')
cd.flowers <- coldist(vis.flowers, n = c(1, 1, 1))
jnd.flowers <- jnd2xyz(cd.flowers)

expect_equal(digest::sha1(jndrot(jnd2xyz(coldist(vismodel(flowers, achromatic = 'bt.dc', relative = FALSE), achromatic = TRUE)))), "494011011cd570e76cbd0209bbe41fc4830794e3")


# Errors
expect_equal(dim(jnd2xyz(cd.flowers)), c(36, 2))
expect_equal(dim(coldist(vismodel(flowers))), c(630, 3))

rownames(attr(jnd.flowers, 'resref'))[4] <- 'nope'
expect_error(jndrot(jnd.flowers), 'does not match')

class(jnd.flowers) <- 'data.frame'
expect_error(jndrot(jnd.flowers), 'jnd2xyz')


})

test_that("Output regression", {
library(digest)
data(flowers)
expect_equal(digest::sha1(coldist(colspace(vismodel(flowers, visual = 'canis', achromatic = 'all')), n = c(1, 2), achromatic = TRUE, subset = 'Hibbertia_acicularis')), "52608948cbe4c304909499bbfe09c4694c8e1377") # dispace
expect_equal(digest::sha1(coldist(colspace(vismodel(flowers, visual = 'apis', achromatic = 'all', relative = FALSE, vonkries = TRUE), space = 'hexagon'), n = c(1, 2), achromatic = TRUE, subset = c('Hibbertia_acicularis', 'Grevillea_buxifolia'))), "7cb1b6cf1fdf586413dd954b476fa7cd27d6f283") # dispace
})

test_that("bootcoldist", {
Expand All @@ -70,5 +91,4 @@ test_that("bootcoldist", {
#expect_equal(digest::sha1(bootcoldist(vm, by = gr, n = c(1, 2, 3), weber = 0.1, weber.achro = 0.1, cores = 1)), "67116b67a619e14189e65807a039be1fac6a4077")
expect_equal(dim(bootcoldist(vm, by = gr, n = c(1, 2, 3), weber = 0.1, weber.achro = 0.1, cores = 1)), c(3, 6))

})

})
40 changes: 40 additions & 0 deletions tests/testthat/test-colspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,46 @@ test_that("Errors/messages", {
expect_warning(colspace(vis.flowers, space = 'segment'), 'vismodel')
expect_warning(colspace(vis.flowers, space = 'segment'), 'transformed')

# Coc
expect_error(colspace(vismodel(flowers, visual = 'canis'), space = 'coc'), 'trichromatic')
fak <- sensmodel(c(300, 400, 500, 600))
expect_warning(colspace(vismodel(flowers, visual = fak, relative = FALSE, qcatch = 'Ei', vonkries = TRUE), space = 'coc'), 'first')
expect_warning(colspace(vismodel(flowers, visual = fak, relative = FALSE, qcatch = 'Ei', vonkries = TRUE), space = 'coc'), 'trichromatic')
expect_error(colspace(vismodel(flowers, visual = 'apis', relative = TRUE, qcatch = 'Ei', vonkries = TRUE), space = 'coc'), 'relative')
expect_error(colspace(vismodel(flowers, visual = 'apis', relative = FALSE, qcatch = 'Qi', vonkries = TRUE), space = 'coc'), 'hyperbolically')
expect_error(colspace(vismodel(flowers, visual = 'apis', relative = FALSE, qcatch = 'Ei', vonkries = FALSE), space = 'coc'), 'von-Kries')

vis.flowers <- vismodel(flowers, visual = 'apis', relative = FALSE, qcatch = 'Ei', vonkries = TRUE)
class(vis.flowers) <- 'data.frame'

expect_error(colspace(vis.flowers[1:2], space = 'coc'), 'fewer than three')
expect_warning(colspace(vis.flowers, space = 'coc'), 'treating columns as')
expect_warning(colspace(cbind(vis.flowers, vis.flowers[,2]), space = 'coc'), 'has more than three')

vis.flowers <- vismodel(flowers, visual = 'apis', relative = TRUE, qcatch = 'Ei', vonkries = TRUE)
class(vis.flowers) <- 'data.frame'
expect_error(colspace(vis.flowers, space = 'coc'), 'relative')

# Hexagon
expect_error(colspace(vismodel(flowers, visual = 'canis'), space = 'hexagon'), 'trichromatic')
fak <- sensmodel(c(300, 400, 500, 600))
expect_error(colspace(vismodel(flowers, visual = 'apis', relative = TRUE), space = 'hexagon'), 'relative')
expect_warning(colspace(vismodel(flowers, visual = fak, relative = FALSE), space = 'hexagon'), 'first three')
expect_warning(colspace(vismodel(flowers, visual = 'apis', relative = FALSE, vonkries = FALSE), space = 'hexagon'), 'hyperbolically')
expect_warning(colspace(vismodel(flowers, visual = 'apis', relative = FALSE, vonkries = FALSE), space = 'hexagon'), 'von-Kries')

vis.flowers <- vismodel(flowers, visual = 'apis', relative = FALSE, qcatch = 'Ei', vonkries = TRUE)
class(vis.flowers) <- 'data.frame'
names(vis.flowers)[1] <- 'a'

expect_error(colspace(vis.flowers[1:2], space = 'hexagon'), 'fewer than three')
expect_warning(colspace(vis.flowers, space = 'hexagon'), 'treating columns as')
expect_warning(colspace(cbind(vis.flowers, vis.flowers[,2]), space = 'hexagon'), 'has more than three')

vis.flowers <- vismodel(flowers, visual = 'apis', relative = TRUE, qcatch = 'Ei', vonkries = TRUE)
class(vis.flowers) <- 'data.frame'
expect_error(colspace(vis.flowers, space = 'hexagon'), 'relative')

})

test_that("Output regression", {
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-general.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ test_that("Class assignment", {

test_that("plot utilities", {
data(sicalis)
# expect_known_hash(spec2rgb(sicalis), "0d3e41a7b6")

expect_error(spec2rgb(sicalis[300:nrow(sicalis), ]), "full visible range")
expect_error(spec2rgb(sicalis[, -1]), "No wavelengths supplied")
})

test_that("sensdata", {

expect_true(all(names(as.data.frame(vissyst)) %in% names(sensdata('all', 'all'))))

})

test_that("peakshape", {
data(flowers)

expect_equivalent(round(colSums(peakshape(flowers, select = 1:5, lim = c(300, 700), plot = FALSE)[2:3])), c(916, 3317))
})

0 comments on commit f25b7cb

Please sign in to comment.