From 3642c1d2772b701c15f79b76d6f0f86cf076d022 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Sat, 22 May 2021 12:26:50 -0700 Subject: [PATCH] update expectation for test to fix #241 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 --- tests/testthat/test-values.R | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-values.R b/tests/testthat/test-values.R index 5070f2c8..f773c9c6 100644 --- a/tests/testthat/test-values.R +++ b/tests/testthat/test-values.R @@ -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])