tests/testthat/test-plotScatter.R

# context("test-plotScatter")

X <- matrix(rnorm(200), nrow = 10, ncol = 20)
Y1 <- matrix(rnorm(200), nrow = 10, ncol = 20)
X1 <- matrix(rnorm(200), nrow = 5)
X2 <- c(1,2,3,4,5)
Y2 <- c(1,2,3,4,5)
groups1 <- c(rep("A",5),rep("B",5))
groups <- rep("A",5)
out <- PMA::CCA(X, Y1, typex = "standard", typez="standard", penaltyx = 0.5, penaltyz = 0.5, K=1, standardize = F, trace = F)
out1 <- PMA::CCA(X, Y1, typex = "standard", typez="standard", penaltyx = 0.5, penaltyz = 0.5, K=3, standardize = F, trace = F)
out2 <- NULL
test_that("Can identify correct input", {
  expect_error(plotScatter(X1, Y1, K = 1, groups = groups1, CCA_out = out1))
  expect_error(plotScatter(X1, Y1, K = 1, groups = groups, CCA_out = out1))
  expect_error(plotScatter(X1, Y1, K = "1", groups = groups1, CCA_out = out1))
  expect_error(plotScatter(X2, Y1,  K = 1, groups = groups1, CCA_out = out1))
  expect_error(plotScatter(X, Y2,  K = 1, groups = groups1, CCA_out = out1))
  # expect_error(plotScatter(X, Y1,  K = 1, groups = groups1, CCA_out = out1))
  expect_error(plotScatter(X, Y1, K = 2, groups = groups1, CCA_out = out))
  expect_error(plotScatter(X, Y1, K = 1, groups = groups1, CCA_out = out2))
})


test_that("Can output correct values", {
  expect_length(plotScatter(X, Y1, K = 1, groups = groups1, CCA_out = out1), 1)
  expect_length(plotScatter(X, Y1, K = 2, groups = groups1, CCA_out = out1), 2)
})
YunhuiQi/TestPMD documentation built on May 5, 2022, 8:23 p.m.