Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itcarroll committed Jan 9, 2019
1 parent 1d19e1e commit 0346164
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions R/multivariate_change_and_difference.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ multivariate_difference <- function(df,

# compute time.var2 change from time.var
output$dispersion_diff <- output$dispersion2 - output$dispersion
output$trt_greater_disp <- ifelse(as.numeric(output$dispersion_diff) < 0,
output[[treatment.var]],
output[[treatment.var2]])
idx <- as.numeric(output$dispersion_diff) < 0
output$trt_greater_disp <- output[[treatment.var]]
output$trt_greater_disp[idx] <- output[[treatment.var2]][idx]
output$abs_dispersion_diff <- abs(output$dispersion_diff)
output$composition_diff <- mapply(
function(x, y) {z <- x - y; sqrt(sum(z*z))},
Expand Down Expand Up @@ -355,7 +355,7 @@ dblctr <- function(d) {

# Calculate a full Bray Curtis dissimilarity matrix
# @param a abundance matrix (columns are species, rows are observations) with no missing values
# FIXME should probably implement in c
# FIXME should probably implement in C
braycurtis <- function(a) {
n <- nrow(a)
ij <- combn(n, 2)
Expand Down
11 changes: 10 additions & 1 deletion tests/testthat/test_multivariate_change.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("multivariate_change function returns correct result", {
expect_is(myresults1, "data.frame")
expect_equal(nrow(myresults1), 3)
expect_equal(ncol(myresults1), 4)
expect_equal(myresults1$composition_change[1], 0.1325553, tolerance = 0.00001)
expect_equal(myresults1$composition_change[1], 0.1244439, tolerance = 0.00001)
expect_equal(myresults1$dispersion_change[1], 0.03804344, tolerance = 0.000001)

#test that it works with treatment
Expand Down Expand Up @@ -70,4 +70,13 @@ test_that("multivariate_change function returns correct result", {
species.var = "species",
time.var = "year"), "Multiple records for one or more species found at:\n year plot\n \"2002\" \"25\"")

# imaginary distance generates warning
df <- data.frame(
t = rep(0:1, each = 6),
r = rep(0:2, each = 2),
s = rep(c('a', 'b'), 6),
a = c(0, 2, 1, 2, 1, 0, 1, 2, 1, 2, 1, 2)
)
expect_warning(multivariate_change(df,
time.var = 't', replicate.var = 'r', species.var = 's', abundance.var = 'a'))
})
2 changes: 1 addition & 1 deletion tests/testthat/test_multivariate_difference.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("multivariate_difference function returns correct result", {
expect_is(myresults1, "data.frame")
expect_equal(nrow(myresults1), 2)
expect_equal(ncol(myresults1), 5)
expect_equal(myresults1$composition_diff[1], 0.08895478, tolerance = 0.00001)
expect_equal(myresults1$composition_diff[1], 0.07108743, tolerance = 0.00001)
expect_equal(myresults1$abs_dispersion_diff[1], 0.01123982, tolerance = 0.000001)

#test that it works with time and reference treatment
Expand Down

0 comments on commit 0346164

Please sign in to comment.