Skip to content

Commit

Permalink
update expectation for test to fix #241
Browse files Browse the repository at this point in the history
It's worth noting that this test was _not incorrect_ numerically because
it was only considering the output from the distance matrix, which was a
lower triangle. Because the values that are recycled end up being thrown
away in the distance object, it was okay for us to construct one without
needing to supply the other side of the matrix.

This fixes the issue by adding a helper function to fill in the correct
values of the matrix and then convert to a distance to avoid the error
thrown by R when not supplying a vector with the correct number of
values for the matrix
  • Loading branch information
zkamvar committed May 22, 2021
1 parent 294c2ea commit 3642c1d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/testthat/test-values.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ test_that("Bruvo between creates a subset of bruvo's distance", {
ADDloss <- bruvo.between(querygid, refgid, add = TRUE, loss = FALSE)
addLOSS <- bruvo.between(querygid, refgid, add = FALSE, loss = TRUE)
ADDLOSS <- bruvo.between(querygid, refgid, add = TRUE, loss = TRUE)
# Create expected distance matrix from bruvo.between()
make_AL_expect <- function(n) {
as.dist(matrix(
c(0, 0, n,
0, 0, NaN,
n, NaN, 0),
nrow = 3, ncol = 3))
}
# Values from Bruvo et. al. (2004)
expected_addloss <- as.dist(matrix(c(0, 0, 0.46875000000000, NaN, NaN, NaN), ncol=3, nrow=3))
expected_ADDloss <- as.dist(matrix(c(0, 0, 0.458333164453506, NaN, NaN, NaN), ncol=3, nrow=3))
expected_addLOSS <- as.dist(matrix(c(0, 0, 0.34374987334013, NaN, NaN, NaN), ncol=3, nrow=3))
expected_ADDLOSS <- as.dist(matrix(c(0, 0, 0.401041518896818, NaN, NaN, NaN), ncol=3, nrow=3))
expected_addloss <- make_AL_expect(0.46875000000000)
expected_addLOSS <- make_AL_expect(0.34374987334013)
expected_ADDloss <- make_AL_expect(0.458333164453506)
expected_ADDLOSS <- make_AL_expect(0.401041518896818)

expect_equal(addloss[1:2], expected_addloss[1:2])
expect_equal(is.nan(addloss[3]), TRUE)
expect_equal(ADDloss[1:2], expected_ADDloss[1:2])
Expand Down

0 comments on commit 3642c1d

Please sign in to comment.