From f9218735ab7f53beedd8733952320a7ec66354cd Mon Sep 17 00:00:00 2001 From: Max-Bladen Date: Wed, 16 Nov 2022 09:12:07 +1100 Subject: [PATCH] Fix for Issue #266 tests: added test to maintain coverage --- tests/testthat/test-auroc.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/testthat/test-auroc.R b/tests/testthat/test-auroc.R index 1b10405c..74981fc2 100644 --- a/tests/testthat/test-auroc.R +++ b/tests/testthat/test-auroc.R @@ -21,3 +21,27 @@ test_that("auroc works", { rbind(0.9981, 7.124e-09)) }) + + + +test_that("Safely handles zero var (non-zero center) features", { + + X1 <- data.frame(matrix(rnorm(100000, 5, 5), nrow = 100)) + X2 <- data.frame(matrix(rnorm(150000, 5, 5), nrow = 100)) + Y <- c(rep("A", 50), rep("B", 50)) + + X <- list(block1=X1, block2=X2) + + list.keepX <- list(block1=c(15, 15), block2=c(30,30)) + + X$block1[,1] <- rep(1, 100) + model = suppressWarnings(block.splsda(X = X, Y = Y, ncomp = 2, + keepX = list.keepX, design = "full")) + + set.seed(9425) + auc.splsda = .quiet(auroc(model)) + + .expect_numerically_close(auc.splsda$block1$comp1[[1]], 0.815) + .expect_numerically_close(auc.splsda$block2$comp2[[2]], 2.22e-16) + +}) \ No newline at end of file